Changeset 3431
- Timestamp:
- May 5, 2009, 6:42:08 PM (13 years ago)
- Location:
- neercs/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
neercs/trunk/TODO
r3337 r3431 3 3 * Autolock after n seconds of screensaver 4 4 * Autolock on detach 5 - Have a way to detect that the server died when we are already connected6 - Allow people to have a window bigger than my screen7 5 - Improve performance -
neercs/trunk/src/main.c
r3324 r3431 159 159 char buf[128*1024]; 160 160 if(!screen_list) goto end; 161 if 161 if(screen_list->socket[SOCK_CLIENT] && (n = read(screen_list->socket[SOCK_CLIENT], buf, sizeof(buf)-1)) > 0) 162 162 { 163 163 buf[n] = 0; … … 170 170 else if(!strncmp("REFRESH ", buf, 8)) 171 171 { 172 caca_import_memory(screen_list->cv, buf+8, n-8, "caca"); 172 ssize_t l2 = 0, lb = n-8; 173 char * buf2 = NULL; 174 size_t l = caca_import_memory(screen_list->cv, buf+8, lb, "caca"); 175 /* 0 means we have valid data but incomplete, so read the rest */ 176 if(l == 0) 177 { 178 buf2 = realloc(buf2, lb+l2); 179 memcpy(buf2+l2, buf+8, lb); 180 l2 += lb; 181 } 182 while(l == 0) 183 { 184 fcntl(screen_list->socket[SOCK_CLIENT], F_SETFL, 0); 185 lb = read(screen_list->socket[SOCK_CLIENT], buf, sizeof(buf)-1); 186 if(lb < 0) 187 { 188 debug("Failed to read the end of the refresh message (%s)", strerror(errno)); 189 l = -1; 190 } 191 else 192 { 193 debug("Got %d more bytes", lb); 194 buf2 = realloc(buf2, lb+l2); 195 memcpy(buf2+l2, buf, lb); 196 l2 += lb; 197 l = caca_import_memory(screen_list->cv, buf2, l2, "caca"); 198 } 199 } 200 fcntl(screen_list->socket[SOCK_CLIENT], F_SETFL, O_NONBLOCK); 173 201 caca_refresh_display(screen_list->dp); 174 202 } -
neercs/trunk/src/server.c
r3396 r3431 24 24 #include <signal.h> 25 25 #include <sys/ioctl.h> 26 #include <sys/socket.h> 26 27 #include <sys/types.h> 27 28 #include <sys/wait.h> … … 40 41 if(!screen_list->socket[SOCK_CLIENT]) 41 42 connect_socket(screen_list, SOCK_CLIENT); 42 debug("Sending message (% s) to client on socket %d", msg, screen_list->socket[SOCK_CLIENT]);43 debug("Sending message (%.8s,%d) to client on socket %d", msg, strlen(msg), screen_list->socket[SOCK_CLIENT]); 43 44 if(!screen_list->socket[SOCK_CLIENT]) 44 45 ret = -1; … … 106 107 connect_socket(screen_list, SOCK_CLIENT); 107 108 if(screen_list->socket[SOCK_CLIENT]) 108 if(write(screen_list->socket[SOCK_CLIENT], buf2, bytes+8) <= 0 && errno != EAGAIN) 109 { 110 debug("Can't refresh (%s), with %d bytes\n", strerror(errno), bytes+8); 109 { 110 size_t bufsize, towrite = bytes+8; 111 ssize_t written; 112 socklen_t optlen = sizeof(bufsize); 113 debug("Requesting refresh for %d", bytes+8); 114 getsockopt(screen_list->socket[SOCK_CLIENT], SOL_SOCKET, SO_SNDBUF, 115 &bufsize, &optlen); 116 written = write(screen_list->socket[SOCK_CLIENT], 117 buf2, 118 towrite > bufsize ? bufsize : towrite); 119 if(written <= 0 && errno != EAGAIN) 120 { 121 debug("Can't refresh (%s), with %d bytes", strerror(errno), towrite); 111 122 return -1; 112 123 } 124 debug("Wrote %d bytes", written); 125 towrite -= written; 126 while(written > 0 && towrite > 0) 127 { 128 ssize_t n; 129 debug("Wrote %d, %d remaining", written, towrite); 130 /* Block to read the end of the message */ 131 fcntl(screen_list->socket[SOCK_CLIENT], F_SETFL, 0); 132 n = write(screen_list->socket[SOCK_CLIENT], 133 buf2 + written, 134 towrite > bufsize ? bufsize : towrite); 135 if(n < 0) 136 { 137 debug("Can't refresh (%s), with %d bytes", strerror(errno), bytes+8); 138 return -1; 139 } 140 written += n; 141 towrite -= n; 142 } 143 fcntl(screen_list->socket[SOCK_CLIENT], F_SETFL, O_NONBLOCK); 144 } 113 145 free(buf); 114 146 free(buf2);
Note: See TracChangeset
for help on using the changeset viewer.