Changeset 426

Show
Ignore:
Timestamp:
10/07/06 16:17:50 (2 years ago)
Author:
alo
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • cherokee/trunk/ChangeLog

    r424 r426  
     12006-10-07  A.D.F  <adefacc@tin.it> 
     2 
     3        * cherokee/thread.c, cherokee/socket.c, cherokee/socket.h: Better 
     4        fd management. Fixes a few problems with fd leaks. 
     5 
    162006-10-03  A.D.F  <adefacc@tin.it> 
    27 
  • cherokee/trunk/cherokee/admin_server.c

    r384 r426  
    2424 
    2525#include "admin_server.h" 
    26 #include "util.h" 
    2726#include "server-protected.h" 
    2827#include "connection-protected.h" 
    2928#include "connection_info.h" 
     29#include "util.h" 
     30 
    3031 
    3132/* Server Port 
  • cherokee/trunk/cherokee/socket.c

    r392 r426  
    445445cherokee_socket_close (cherokee_socket_t *socket) 
    446446{ 
    447         int re; 
    448  
    449447        if (socket->socket < 0) { 
    450448                return ret_error; 
     
    482480cherokee_socket_shutdown (cherokee_socket_t *socket, int how) 
    483481{ 
    484         int re; 
    485  
    486482        /* If the read side of the socket has been closed but the 
    487483         * write side is not, then don't bother to call shutdown 
     
    494490                return ret_error; 
    495491 
    496         re = shutdown (socket->socket, how);     
    497  
    498         return (re == 0) ? ret_ok : ret_error; 
     492        if (unlikely (shutdown (socket->socket, how) != 0)) 
     493                return ret_error; 
     494 
     495        return ret_ok; 
    499496} 
    500497 
     
    580577 
    581578        ret = cherokee_socket_set_sockaddr (socket, fd, &sa); 
    582         if (unlikely(ret < ret_ok)) return ret; 
     579        if (unlikely(ret < ret_ok)) { 
     580                cherokee_close_fd (socket); 
     581                return ret; 
     582        } 
    583583 
    584584        return ret_ok; 
     
    605605 
    606606        memcpy (&socket->client_addr, sa, socket->client_addr_len); 
     607 
     608        /* Status is no more closed. 
     609         */ 
     610        socket->status = socket_reading; 
    607611         
    608612        SOCKET_FD(socket) = fd; 
     
    624628                return ret_error; 
    625629        }                
    626  
    627         /* Close-on-exec 
    628          */ 
    629         CLOSE_ON_EXEC (new_socket); 
    630630         
    631631        /* Disable Nagle's algorithm for this connection. 
     
    635635        setsockopt (new_socket, IPPROTO_TCP, TCP_NODELAY, (const void *)&tmp, sizeof(tmp)); 
    636636         
     637        /* Close-on-exec 
     638         */ 
     639        CLOSE_ON_EXEC (new_socket); 
     640 
    637641        /* Enables nonblocking I/O. 
    638642         */ 
  • cherokee/trunk/cherokee/thread.c

    r389 r426  
    13061306 
    13071307        /* We got the new socket, now set it up in a new connection object 
    1308         */ 
     1308        */ 
    13091309        ret = cherokee_thread_get_new_connection (thd, &new_conn); 
    13101310        if (unlikely(ret < ret_ok)) { 
    13111311                PRINT_ERROR_S ("ERROR: Trying to get a new connection object\n"); 
     1312                cherokee_close_fd (new_fd); 
    13121313                return 0; 
    13131314        } 
    13141315 
    13151316        ret = cherokee_socket_set_sockaddr (&new_conn->socket, new_fd, &new_sa); 
    1316         if (unlikely(ret < ret_ok)) goto error; 
     1317        if (unlikely(ret < ret_ok)) { 
     1318                PRINT_ERROR_S ("ERROR: Trying to set sockaddr\n"); 
     1319                cherokee_close_fd (new_fd); 
     1320                goto error; 
     1321        } 
    13171322 
    13181323        /* May active the TLS support 
  • cherokee/trunk/cherokee/util.c

    r405 r426  
    12481248        return ret_no_sys; 
    12491249} 
     1250 
     1251 
     1252ret_t  
     1253cherokee_close_fd (cint_t fd) 
     1254{ 
     1255        int re; 
     1256         
     1257        if (fd < 0) { 
     1258                return ret_error; 
     1259        } 
     1260         
     1261#ifdef _WIN32 
     1262        re = closesocket (fd); 
     1263#else   
     1264        re = close (fd); 
     1265#endif 
     1266 
     1267        TRACE (ENTRIES",close_fd", "fd=%d re=%d\n", fd, re); 
     1268         
     1269        return (re == 0) ? ret_ok : ret_error; 
     1270} 
  • cherokee/trunk/cherokee/util.h

    r399 r426  
    103103ret_t cherokee_sys_fdlimit_get (cuint_t *limit); 
    104104ret_t cherokee_sys_fdlimit_set (cuint_t  limit); 
     105ret_t cherokee_close_fd        (cint_t fd); 
    105106void  cherokee_trace (const char *entry, const char *file, int line, const char *func, const char *fmt, ...); 
    106107