make Conn_NewListener local to conn.c
This commit is contained in:
parent
70facb7f6e
commit
4715b17106
|
@ -17,7 +17,7 @@
|
||||||
#include "portab.h"
|
#include "portab.h"
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
|
|
||||||
static char UNUSED id[] = "$Id: conn.c,v 1.160 2005/07/11 14:11:35 fw Exp $";
|
static char UNUSED id[] = "$Id: conn.c,v 1.161 2005/07/11 14:56:38 fw Exp $";
|
||||||
|
|
||||||
#include "imp.h"
|
#include "imp.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
@ -94,6 +94,7 @@ LOCAL bool Init_Socket PARAMS(( int Sock ));
|
||||||
LOCAL void New_Server PARAMS(( int Server, CONN_ID Idx ));
|
LOCAL void New_Server PARAMS(( int Server, CONN_ID Idx ));
|
||||||
LOCAL void Simple_Message PARAMS(( int Sock, char *Msg ));
|
LOCAL void Simple_Message PARAMS(( int Sock, char *Msg ));
|
||||||
LOCAL int Count_Connections PARAMS(( struct sockaddr_in addr ));
|
LOCAL int Count_Connections PARAMS(( struct sockaddr_in addr ));
|
||||||
|
LOCAL int NewListener PARAMS(( const UINT16 Port ));
|
||||||
|
|
||||||
static array My_Listeners;
|
static array My_Listeners;
|
||||||
|
|
||||||
|
@ -278,7 +279,7 @@ Conn_InitListeners( void )
|
||||||
{
|
{
|
||||||
/* Initialize ports on which the server should accept connections */
|
/* Initialize ports on which the server should accept connections */
|
||||||
|
|
||||||
int created;
|
int created, fd;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
if (!io_library_init(CONNECTION_POOL)) {
|
if (!io_library_init(CONNECTION_POOL)) {
|
||||||
|
@ -287,10 +288,19 @@ Conn_InitListeners( void )
|
||||||
}
|
}
|
||||||
|
|
||||||
created = 0;
|
created = 0;
|
||||||
for( i = 0; i < Conf_ListenPorts_Count; i++ )
|
for( i = 0; i < Conf_ListenPorts_Count; i++ ) {
|
||||||
{
|
fd = NewListener( Conf_ListenPorts[i] );
|
||||||
if( Conn_NewListener( Conf_ListenPorts[i] )) created++;
|
if (fd < 0) {
|
||||||
else Log( LOG_ERR, "Can't listen on port %u!", (unsigned int) Conf_ListenPorts[i] );
|
Log( LOG_ERR, "Can't listen on port %u!", (unsigned int) Conf_ListenPorts[i] );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!io_event_create( fd, IO_WANTREAD, cb_listen )) {
|
||||||
|
Log( LOG_ERR, "io_event_create(): Could not add listening fd %d (port %u): %s!",
|
||||||
|
fd, (unsigned int) Conf_ListenPorts[i], strerror(errno));
|
||||||
|
close(fd);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
created++;
|
||||||
}
|
}
|
||||||
return created;
|
return created;
|
||||||
} /* Conn_InitListeners */
|
} /* Conn_InitListeners */
|
||||||
|
@ -323,8 +333,8 @@ Conn_ExitListeners( void )
|
||||||
} /* Conn_ExitListeners */
|
} /* Conn_ExitListeners */
|
||||||
|
|
||||||
|
|
||||||
GLOBAL bool
|
LOCAL int
|
||||||
Conn_NewListener( const UINT16 Port )
|
NewListener( const UINT16 Port )
|
||||||
{
|
{
|
||||||
/* Create new listening socket on specified port */
|
/* Create new listening socket on specified port */
|
||||||
|
|
||||||
|
@ -350,7 +360,7 @@ Conn_NewListener( const UINT16 Port )
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
Log( LOG_CRIT, "Can't listen on %s:%u: can't convert ip address %s!", Conf_ListenAddress, Port, Conf_ListenAddress );
|
Log( LOG_CRIT, "Can't listen on %s:%u: can't convert ip address %s!", Conf_ListenAddress, Port, Conf_ListenAddress );
|
||||||
return false;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else inaddr.s_addr = htonl( INADDR_ANY );
|
else inaddr.s_addr = htonl( INADDR_ANY );
|
||||||
|
@ -361,17 +371,17 @@ Conn_NewListener( const UINT16 Port )
|
||||||
if( sock < 0 )
|
if( sock < 0 )
|
||||||
{
|
{
|
||||||
Log( LOG_CRIT, "Can't create socket: %s!", strerror( errno ));
|
Log( LOG_CRIT, "Can't create socket: %s!", strerror( errno ));
|
||||||
return false;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ! Init_Socket( sock )) return false;
|
if( ! Init_Socket( sock )) return -1;
|
||||||
|
|
||||||
/* an Port binden */
|
/* an Port binden */
|
||||||
if( bind( sock, (struct sockaddr *)&addr, (socklen_t)sizeof( addr )) != 0 )
|
if( bind( sock, (struct sockaddr *)&addr, (socklen_t)sizeof( addr )) != 0 )
|
||||||
{
|
{
|
||||||
Log( LOG_CRIT, "Can't bind socket: %s!", strerror( errno ));
|
Log( LOG_CRIT, "Can't bind socket: %s!", strerror( errno ));
|
||||||
close( sock );
|
close( sock );
|
||||||
return false;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* in "listen mode" gehen :-) */
|
/* in "listen mode" gehen :-) */
|
||||||
|
@ -379,16 +389,15 @@ Conn_NewListener( const UINT16 Port )
|
||||||
{
|
{
|
||||||
Log( LOG_CRIT, "Can't listen on soecket: %s!", strerror( errno ));
|
Log( LOG_CRIT, "Can't listen on soecket: %s!", strerror( errno ));
|
||||||
close( sock );
|
close( sock );
|
||||||
return false;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Neuen Listener in Strukturen einfuegen */
|
/* Neuen Listener in Strukturen einfuegen */
|
||||||
if (!array_catb( &My_Listeners,(char*) &sock, sizeof(int) )) {
|
if (!array_catb( &My_Listeners,(char*) &sock, sizeof(int) )) {
|
||||||
Log( LOG_CRIT, "Can't add socket to My_Listeners array: %s!", strerror( errno ));
|
Log( LOG_CRIT, "Can't add socket to My_Listeners array: %s!", strerror( errno ));
|
||||||
close( sock );
|
close( sock );
|
||||||
return false;
|
return -1;
|
||||||
}
|
}
|
||||||
io_event_create( sock, IO_WANTREAD, cb_listen );
|
|
||||||
|
|
||||||
if( Conf_ListenAddress[0]) Log( LOG_INFO, "Now listening on %s:%d (socket %d).", Conf_ListenAddress, Port, sock );
|
if( Conf_ListenAddress[0]) Log( LOG_INFO, "Now listening on %s:%d (socket %d).", Conf_ListenAddress, Port, sock );
|
||||||
else Log( LOG_INFO, "Now listening on 0.0.0.0:%d (socket %d).", Port, sock );
|
else Log( LOG_INFO, "Now listening on 0.0.0.0:%d (socket %d).", Port, sock );
|
||||||
|
@ -420,8 +429,8 @@ Conn_NewListener( const UINT16 Port )
|
||||||
/* Register service */
|
/* Register service */
|
||||||
Rendezvous_Register( name, MDNS_TYPE, Port );
|
Rendezvous_Register( name, MDNS_TYPE, Port );
|
||||||
#endif
|
#endif
|
||||||
return true;
|
return sock;
|
||||||
} /* Conn_NewListener */
|
} /* NewListener */
|
||||||
|
|
||||||
|
|
||||||
GLOBAL void
|
GLOBAL void
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
* Please read the file COPYING, README and AUTHORS for more information.
|
* Please read the file COPYING, README and AUTHORS for more information.
|
||||||
*
|
*
|
||||||
* $Id: conn.h,v 1.36 2005/07/07 18:45:33 fw Exp $
|
* $Id: conn.h,v 1.37 2005/07/11 14:56:38 fw Exp $
|
||||||
*
|
*
|
||||||
* Connection management (header)
|
* Connection management (header)
|
||||||
*/
|
*/
|
||||||
|
@ -84,8 +84,6 @@ GLOBAL void Conn_Exit PARAMS(( void ));
|
||||||
GLOBAL int Conn_InitListeners PARAMS(( void ));
|
GLOBAL int Conn_InitListeners PARAMS(( void ));
|
||||||
GLOBAL void Conn_ExitListeners PARAMS(( void ));
|
GLOBAL void Conn_ExitListeners PARAMS(( void ));
|
||||||
|
|
||||||
GLOBAL bool Conn_NewListener PARAMS(( const UINT16 Port ));
|
|
||||||
|
|
||||||
GLOBAL void Conn_Handler PARAMS(( void ));
|
GLOBAL void Conn_Handler PARAMS(( void ));
|
||||||
|
|
||||||
GLOBAL bool Conn_Write PARAMS(( CONN_ID Idx, char *Data, unsigned int Len ));
|
GLOBAL bool Conn_Write PARAMS(( CONN_ID Idx, char *Data, unsigned int Len ));
|
||||||
|
|
Loading…
Reference in New Issue