Changeset 6283c63bb120fef59d85d0f8fbf16d89c6c99224
- Timestamp:
- 27/02/03 16:07:48 (6 years ago)
- git-parent:
- Files:
-
- modules/misc/httpd.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
modules/misc/httpd.c
r626d8be r6283c63 3 3 ***************************************************************************** 4 4 * Copyright (C) 2001-2003 VideoLAN 5 * $Id: httpd.c,v 1. 3 2003/02/25 17:17:43fenrir Exp $5 * $Id: httpd.c,v 1.4 2003/02/27 15:07:48 fenrir Exp $ 6 6 * 7 7 * Authors: Laurent Aimar <fenrir@via.ecp.fr> … … 26 26 *****************************************************************************/ 27 27 #include <stdlib.h> 28 29 #include <sys/time.h> 28 30 #include <sys/types.h> 29 31 #include <sys/stat.h> 32 30 33 #include <string.h> 31 34 #include <errno.h> … … 67 70 #endif 68 71 69 #define LISTEN_BACKLOG 10070 #define HTTPD_MAX_CONNECTION 102471 72 #define LISTEN_BACKLOG 100 73 #define HTTPD_MAX_CONNECTION 512 74 #define HTTPD_CONNECTION_MAX_UNUSED 10000000 72 75 73 76 #define FREE( p ) if( p ) { free( p); (p) = NULL; } … … 176 179 struct httpd_connection_s *p_prev; 177 180 178 struct sockaddr_in sock; 179 int fd; 181 struct sockaddr_in sock; 182 int fd; 183 mtime_t i_last_activity_date; 180 184 181 185 int i_state; … … 958 962 p += sprintf( p, "<h2><center>Admin page</center></h2>\n" ); 959 963 964 /* general */ 965 p += sprintf( p, "<h3>General state</h3>\n" ); 966 p += sprintf( p, "<ul>\n" ); 967 p += sprintf( p, "<li>Connection count: %d</li>\n", p_httpt->i_connection_count ); 968 //p += sprintf( p, "<li>Total bandwith: %d</li>\n", -1 ); 969 /*p += sprintf( p, "<li></li>\n" );*/ 970 p += sprintf( p, "</ul>\n" ); 960 971 /* host list */ 961 972 vlc_mutex_lock( &p_httpt->host_lock ); … … 1054 1065 p_con->i_state = HTTPD_CONNECTION_RECEIVING_REQUEST; 1055 1066 p_con->fd = fd; 1067 p_con->i_last_activity_date = mdate(); 1068 1056 1069 p_con->sock = *p_sock; 1057 1070 p_con->psz_file = NULL; … … 1403 1416 1404 1417 httpd_connection_t *p_con; 1405 vlc_bool_t b_wait;1406 1418 1407 1419 msg_Info( p_httpt, "httpd started" ); … … 1425 1437 while( !p_httpt->b_die ) 1426 1438 { 1439 struct timeval timeout; 1440 fd_set fds_read; 1441 fd_set fds_write; 1442 int i_handle_max = 0; 1443 int i_ret; 1427 1444 int i; 1428 1445 if( p_httpt->i_host_count <= 0 ) … … 1431 1448 continue; 1432 1449 } 1450 1451 /* we will create a socket set with host and connection */ 1452 FD_ZERO( &fds_read ); 1453 FD_ZERO( &fds_write ); 1454 1455 vlc_mutex_lock( &p_httpt->host_lock ); 1456 vlc_mutex_lock( &p_httpt->connection_lock ); 1457 for( i = 0; i < p_httpt->i_host_count; i++ ) 1458 { 1459 FD_SET( p_httpt->host[i]->fd, &fds_read ); 1460 i_handle_max = __MAX( i_handle_max, p_httpt->host[i]->fd ); 1461 } 1462 for( p_con = p_httpt->p_first_connection; p_con != NULL; ) 1463 { 1464 /* no more than 10s of inactivity */ 1465 if( p_con->i_last_activity_date + (mtime_t)HTTPD_CONNECTION_MAX_UNUSED < mdate() ) 1466 { 1467 httpd_connection_t *p_next = p_con->p_next; 1468 1469 msg_Dbg( p_httpt, "close unused connection" ); 1470 httpd_ConnnectionClose( p_httpt, p_con ); 1471 p_con = p_next; 1472 continue; 1473 } 1474 1475 if( p_con->i_state == HTTPD_CONNECTION_SENDING_STREAM && p_con->i_stream_pos + HTTPD_STREAM_PACKET >= p_con->p_file->i_buffer_pos ) 1476 { 1477 p_con = p_con->p_next; 1478 continue; 1479 } 1480 1481 if( p_con->i_state == HTTPD_CONNECTION_RECEIVING_REQUEST ) 1482 { 1483 FD_SET( p_con->fd, &fds_read ); 1484 } 1485 else 1486 { 1487 FD_SET( p_con->fd, &fds_write ); 1488 } 1489 i_handle_max = __MAX( i_handle_max, p_con->fd ); 1490 1491 p_con = p_con->p_next; 1492 } 1493 vlc_mutex_unlock( &p_httpt->host_lock ); 1494 vlc_mutex_unlock( &p_httpt->connection_lock ); 1495 1496 /* we will wait 0.5s */ 1497 timeout.tv_sec = 0; 1498 timeout.tv_usec = 500*1000; 1499 1500 i_ret = select( i_handle_max + 1, 1501 &fds_read, 1502 &fds_write, 1503 NULL, 1504 &timeout ); 1505 if( i_ret == -1 && errno != EINTR ) 1506 { 1507 msg_Warn( p_httpt, "cannot select sockets" ); 1508 msleep( 1000 ); 1509 continue; 1510 } 1511 if( i_ret <= 0 ) 1512 { 1513 // msg_Dbg( p_httpt, "waiting..." ); 1514 continue; 1515 } 1516 1433 1517 vlc_mutex_lock( &p_httpt->host_lock ); 1434 1518 /* accept/refuse new connection */ … … 1488 1572 { 1489 1573 uint8_t *ptr; 1490 1574 p_con->i_last_activity_date = mdate(); 1491 1575 p_con->i_buffer += i_len; 1492 1576 … … 1528 1612 else if( i_len > 0 ) 1529 1613 { 1614 p_con->i_last_activity_date = mdate(); 1530 1615 p_con->i_buffer += i_len; 1531 1616 … … 1610 1695 else if( i_send > 0 ) 1611 1696 { 1697 p_con->i_last_activity_date = mdate(); 1612 1698 p_con->i_stream_pos += i_send; 1613 1699 } … … 1623 1709 } /* for over connection */ 1624 1710 1625 #if 01626 b_wait = VLC_TRUE;1627 /* update position for stream based file */1628 for( i = 0; i < p_httpt->i_file_count; i++ )1629 {1630 if( p_httpt->file[i]->b_stream )1631 {1632 p_httpt->file[i]->i_buffer += __MIN( p_httpt->file[i]->i_buffer_valid - p_httpt->file[i]->i_buffer,1633 HTTPD_STREAM_PACKET );1634 if( p_httpt->file[i]->i_buffer < p_httpt->file[i]->i_buffer_valid )1635 {1636 /* there is data */1637 b_wait = VLC_FALSE;1638 }1639 }1640 }1641 #endif1642 1711 vlc_mutex_unlock( &p_httpt->file_lock ); 1643 /*if( b_wait )*/ msleep( 10 );1644 1712 } 1645 1713 msg_Info( p_httpt, "httpd stopped" );
