]> git.sesse.net Git - vlc/blobdiff - src/network/httpd.c
More cleanup
[vlc] / src / network / httpd.c
index 26d0f4cd13a4918051262308558c9440e6cffeb5..8b7c883836f87e9d7ed381dc21856d822bf5ee11 100644 (file)
@@ -622,6 +622,7 @@ static int httpd_RedirectCallBack( httpd_callback_sys_t *p_sys,
                                    httpd_message_t *query )
 {
     httpd_redirect_t *rdir = (httpd_redirect_t*)p_sys;
+    char *p_body;
 
     if( answer == NULL || query == NULL )
     {
@@ -633,7 +634,7 @@ static int httpd_RedirectCallBack( httpd_callback_sys_t *p_sys,
     answer->i_status = 301;
     answer->psz_status = strdup( "Moved Permanently" );
 
-    answer->i_body = asprintf( (char **)&answer->p_body,
+    answer->i_body = asprintf( &p_body,
         "<?xml version=\"1.0\" encoding=\"ascii\" ?>\n"
         "<!DOCTYPE html PUBLIC \"-//W3C//DTD  XHTML 1.0 Strict//EN\" "
         "\"http://www.w3.org/TR/xhtml10/DTD/xhtml10strict.dtd\">\n"
@@ -649,6 +650,7 @@ static int httpd_RedirectCallBack( httpd_callback_sys_t *p_sys,
         "<hr />\n"
         "</body>\n"
         "</html>\n", rdir->psz_dst );
+    answer->p_body = (unsigned char *)p_body;
 
     /* XXX check if it's ok or we need to set an absolute url */
     httpd_MsgAdd( answer, "Location",  "%s", rdir->psz_dst );
@@ -1942,10 +1944,10 @@ static void httpd_HostThread( httpd_host_t *host )
 {
     tls_session_t *p_tls = NULL;
 
-    stats_Create( host, "client_connections", STATS_CLIENT_CONNECTIONS,
-                  VLC_VAR_INTEGER, STATS_COUNTER );
-    stats_Create( host, "active_connections", STATS_ACTIVE_CONNECTIONS,
-                  VLC_VAR_INTEGER, STATS_COUNTER );
+    host->p_total_counter = stats_CounterCreate( host,
+                                          VLC_VAR_INTEGER, STATS_COUNTER );
+    host->p_active_counter = stats_CounterCreate( host,
+                                          VLC_VAR_INTEGER, STATS_COUNTER );
 
     while( !host->b_die )
     {
@@ -1995,7 +1997,7 @@ static void httpd_HostThread( httpd_host_t *host )
                     cl->i_activity_date+cl->i_activity_timeout < mdate()) ) ) )
             {
                 httpd_ClientClean( cl );
-                stats_UpdateInteger( host, STATS_ACTIVE_CONNECTIONS, -1, NULL );
+                stats_UpdateInteger( host, host->p_active_counter, -1, NULL );
                 TAB_REMOVE( host->i_client, host->client, cl );
                 free( cl );
                 i_client--;
@@ -2439,7 +2441,10 @@ static void httpd_HostThread( httpd_host_t *host )
 
                 if( fd >= 0 )
                 {
-                    int i_state = 0;
+                    int i_state = 1;
+
+                    setsockopt( fd, SOL_SOCKET, SO_REUSEADDR, &i_state, sizeof (i_state));
+                    i_state = 0;
 
                     /* set this new socket non-block */
 #if defined( WIN32 ) || defined( UNDER_CE )
@@ -2452,7 +2457,7 @@ static void httpd_HostThread( httpd_host_t *host )
                     {
                         int i_val = fcntl( fd, F_GETFL );
                         fcntl( fd, F_SETFL,
-                               O_NONBLOCK | (i_val != -1) ? i_val : 0 );
+                               O_NONBLOCK | ((i_val != -1) ? i_val : 0) );
                     }
 
                     if( fd >= FD_SETSIZE )
@@ -2487,10 +2492,10 @@ static void httpd_HostThread( httpd_host_t *host )
                     {
                         httpd_client_t *cl;
                         char ip[NI_MAXNUMERICHOST];
-                        stats_UpdateInteger( host, STATS_CLIENT_CONNECTIONS,
+                        stats_UpdateInteger( host, host->p_total_counter,
+                                             1, NULL );
+                        stats_UpdateInteger( host, host->p_active_counter,
                                              1, NULL );
-                        stats_UpdateInteger( host, STATS_ACTIVE_CONNECTIONS, 1,
-                                             NULL );
                         cl = httpd_ClientNew( fd, &sock, i_sock_size, p_tls );
                         httpd_ClientIP( cl, ip );
                         msg_Dbg( host, "Connection from %s", ip );