Changeset da7b484
- Timestamp:
- 2008-06-21T17:09:20Z (16 years ago)
- Branches:
- master
- Children:
- edc767b
- Parents:
- d419073
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ipc.c
rd419073 rda7b484 209 209 } 210 210 211 /* Return just one line. Returns NULL if something broke, an empty string 212 on temporary "errors" (EAGAIN and friends). */ 211 213 static char *ipc_readline( int fd ) 212 214 { 213 char *buf, *eol;215 char buf[513], *eol; 214 216 int size; 215 216 buf = g_new0( char, 513 );217 217 218 218 /* Because this is internal communication, it should be pretty safe … … 221 221 sockets and limites message length, messages should always be 222 222 complete. Saves us quite a lot of code and buffering. */ 223 size = recv( fd, buf, 512, MSG_PEEK );223 size = recv( fd, buf, sizeof( buf ) - 1, MSG_PEEK ); 224 224 if( size == 0 || ( size < 0 && !sockerr_again() ) ) 225 225 return NULL; … … 229 229 buf[size] = 0; 230 230 231 eol = strstr( buf, "\r\n" ); 232 if( eol == NULL ) 231 if( ( eol = strstr( buf, "\r\n" ) ) == NULL ) 233 232 return NULL; 234 233 else 235 234 size = eol - buf + 2; 236 237 g_free( buf );238 buf = g_new0( char, size + 1 );239 235 240 236 if( recv( fd, buf, size, 0 ) != size ) 241 237 return NULL; 242 238 else 243 buf[size-2] = 0; 244 245 return buf; 239 return g_strndup( buf, size - 2 ); 246 240 } 247 241
Note: See TracChangeset
for help on using the changeset viewer.