[hackers] [st] Applying a shortening proposal for the run loop of k0ga. || Christoph Lohmann

From: <hg_AT_suckless.org>
Date: Sun, 16 Sep 2012 20:46:02 +0200 (CEST)

changeset: 312:8d36e2eeb58c
tag: tip
user: Christoph Lohmann <20h_AT_r-36.net>
date: Sun Sep 16 20:43:51 2012 +0200
files: st.c
description:
Applying a shortening proposal for the run loop of k0ga.


diff -r da71fbe362ad -r 8d36e2eeb58c st.c
--- a/st.c Sun Sep 16 14:02:35 2012 +0200
+++ b/st.c Sun Sep 16 20:43:51 2012 +0200
_AT_@ -2329,13 +2329,13 @@
         XEvent ev;
         fd_set rfd;
         int xfd = XConnectionNumber(xw.dpy), i;
- struct timeval drawtimeout;
+ struct timeval drawtimeout, *tv = NULL;
 
- for(;;) {
+ for(i = 0;; i++) {
                 FD_ZERO(&rfd);
                 FD_SET(cmdfd, &rfd);
                 FD_SET(xfd, &rfd);
- if(select(MAX(xfd, cmdfd)+1, &rfd, NULL, NULL, NULL) < 0) {
+ if(select(MAX(xfd, cmdfd)+1, &rfd, NULL, NULL, tv) < 0) {
                         if(errno == EINTR)
                                 continue;
                         die("select failed: %s\n", SERRNO);
_AT_@ -2345,23 +2345,20 @@
                  * Stop after a certain number of reads so the user does not
                  * feel like the system is stuttering.
                  */
- for(i = 0; i < 1000 && FD_ISSET(cmdfd, &rfd); i++) {
+ if(i < 1000 && FD_ISSET(cmdfd, &rfd)) {
                         ttyread();
 
- FD_ZERO(&rfd);
- FD_SET(cmdfd, &rfd);
                         /*
                          * Just wait a bit so it isn't disturbing the
                          * user and the system is able to write something.
                          */
                         drawtimeout.tv_sec = 0;
                         drawtimeout.tv_usec = 5;
- if(select(cmdfd+1, &rfd, NULL, NULL, &drawtimeout) < 0) {
- if(errno == EINTR)
- continue;
- die("select failed: %s\n", SERRNO);
- }
+ tv = &drawtimeout;
+ continue;
                 }
+ i = 0;
+ tv = NULL;
 
                 while(XPending(xw.dpy)) {
                         XNextEvent(xw.dpy, &ev);
Received on Sun Sep 16 2012 - 20:46:02 CEST

This archive was generated by hypermail 2.3.0 : Sun Sep 16 2012 - 20:48:06 CEST