Changeset 3438 for neercs/trunk
- Timestamp:
- May 12, 2009, 12:55:01 PM (12 years ago)
- Location:
- neercs/trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
neercs/trunk/src/main.c
r3431 r3438 83 83 long long unsigned int last_key_time = 0; 84 84 int mainret = -1; 85 85 #define NEERCS_RECV_BUFSIZE 128*1024 86 char * buf = NULL; 86 87 87 88 screen_list = create_screen_list(); … … 157 158 int ret = 0; 158 159 ssize_t n; 159 char buf[128*1024];160 160 if(!screen_list) goto end; 161 if(screen_list->socket[SOCK_CLIENT] && (n = read(screen_list->socket[SOCK_CLIENT], buf, sizeof(buf)-1)) > 0) 161 buf = malloc(NEERCS_RECV_BUFSIZE); 162 if(!buf) 163 { 164 debug("Failed to allocate memory"); 165 goto end; 166 } 167 if(screen_list->socket[SOCK_CLIENT] && (n = read(screen_list->socket[SOCK_CLIENT], buf, NEERCS_RECV_BUFSIZE-1)) > 0) 162 168 { 163 169 buf[n] = 0; … … 170 176 else if(!strncmp("REFRESH ", buf, 8)) 171 177 { 172 ssize_t l2 = 0, lb = n-8;173 char * buf2 = NULL;178 ssize_t l2, lb = n-8; 179 char * buf2; 174 180 size_t l = caca_import_memory(screen_list->cv, buf+8, lb, "caca"); 181 l2 = lb; 175 182 /* 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 183 while(l == 0) 183 184 { 185 buf2 = realloc(buf, l2+8 + NEERCS_RECV_BUFSIZE); 186 if(!buf2) 187 { 188 debug("Failed to allocate memory"); 189 goto end; 190 } 191 buf = buf2; 184 192 fcntl(screen_list->socket[SOCK_CLIENT], F_SETFL, 0); 185 lb = read(screen_list->socket[SOCK_CLIENT], buf , sizeof(buf)-1);193 lb = read(screen_list->socket[SOCK_CLIENT], buf+l2+8, NEERCS_RECV_BUFSIZE-1); 186 194 if(lb < 0) 187 195 { … … 192 200 { 193 201 debug("Got %d more bytes", lb); 194 buf2 = realloc(buf2, lb+l2);195 memcpy(buf2+l2, buf, lb);196 202 l2 += lb; 197 l = caca_import_memory(screen_list->cv, buf 2, l2, "caca");203 l = caca_import_memory(screen_list->cv, buf+8, l2, "caca"); 198 204 } 199 205 } … … 233 239 mainret = 0; 234 240 end: 241 if(buf) 242 free(buf); 235 243 if(screen_list) 236 244 { -
neercs/trunk/src/server.c
r3434 r3438 114 114 getsockopt(screen_list->socket[SOCK_CLIENT], SOL_SOCKET, SO_SNDBUF, 115 115 &bufsize, &optlen); 116 bufsize /= 2; 117 debug("bufsize=%d", bufsize); 116 118 written = write(screen_list->socket[SOCK_CLIENT], 117 119 buf2, … … 119 121 if(written <= 0 && errno != EAGAIN) 120 122 { 121 debug("Can't refresh (%s), with %d bytes ", strerror(errno), towrite);123 debug("Can't refresh (%s), with %d bytes (out of %d)", strerror(errno), towrite > bufsize ? bufsize : towrite, towrite); 122 124 return -1; 123 125 }
Note: See TracChangeset
for help on using the changeset viewer.