comparison stream/stream_ftp.c @ 35336:9c334690f765

stream ftp: Revise file descriptor usage * Set unbound descriptor variables to -1 * Always test >= 0 to see if a variable refers to a valid descriptor
author al
date Tue, 20 Nov 2012 22:19:45 +0000
parents 85003f7fa621
children 6641819c8f45
comparison
equal deleted inserted replaced
35335:85003f7fa621 35336:9c334690f765
58 21, 58 21,
59 NULL, 59 NULL,
60 NULL, 60 NULL,
61 NULL, 61 NULL,
62 62
63 0, 63 -1,
64 0,0, 64 0,0,
65 NULL 65 NULL
66 }; 66 };
67 67
68 #define BUFSIZE 2048 68 #define BUFSIZE 2048
357 static const char pre_cmd[]={TELNET_IAC,TELNET_IP,TELNET_IAC,TELNET_SYNCH}; 357 static const char pre_cmd[]={TELNET_IAC,TELNET_IP,TELNET_IAC,TELNET_SYNCH};
358 //int fl; 358 //int fl;
359 359
360 // First close the fd 360 // First close the fd
361 closesocket(s->fd); 361 closesocket(s->fd);
362 s->fd = 0; 362 s->fd = -1;
363 363
364 // Send send the telnet sequence needed to make the server react 364 // Send send the telnet sequence needed to make the server react
365 365
366 // Dunno if this is really needed, lftp have it. I let 366 // Dunno if this is really needed, lftp have it. I let
367 // it here in case it turn out to be needed on some other OS 367 // it here in case it turn out to be needed on some other OS
393 static void close_f(stream_t *s) { 393 static void close_f(stream_t *s) {
394 struct stream_priv_s* p = s->priv; 394 struct stream_priv_s* p = s->priv;
395 395
396 if(!p) return; 396 if(!p) return;
397 397
398 if(s->fd > 0) { 398 if(s->fd >= 0) {
399 closesocket(s->fd); 399 closesocket(s->fd);
400 s->fd = 0; 400 s->fd = -1;
401 } 401 }
402 402
403 FtpSendCmd("QUIT",p,NULL); 403 FtpSendCmd("QUIT",p,NULL);
404 404
405 if(p->handle) closesocket(p->handle); 405 if(p->handle >= 0) closesocket(p->handle);
406 free(p->buf); 406 free(p->buf);
407 407
408 m_struct_free(&stream_opts,p); 408 m_struct_free(&stream_opts,p);
409 } 409 }
410 410