listen/select and then accept pattern not working?
Steve Holle
sholle at link-comm.com
Fri Jan 14 19:02:50 UTC 2005
We are using select on a telnet server. If you would like to have the full
source let me know. This is how we use it
int RecvTimeout ( int s, char *buf, int len, int timeout )
{
fd_set fds ;
int n = 0 ;
struct timeval tv ;
// Set up the file descriptor set.
FD_ZERO(&fds) ;
FD_SET(s, &fds) ;
// Set up the struct timeval for the timeout.
tv.tv_sec = timeout ;
tv.tv_usec = 0 ;
// Wait until timeout or data received.
n = select ( s+1, &fds, NULL, NULL, &tv ) ;
if ( n == 0 ) return -2 ; // Timeout
if ( n == -1 ) return -1 ; // Error
// data must be here, so do a normal recv
return recv ( s, buf, len, 0 ) ;
}
static void TelnetReadTask (rtems_task_argument fd)
{
rtems_unsigned32 count ;
int n = 0 ;
char buffer [ MAX_RLC_IN_MESSAGE_SIZE+1 ] = {0};
TelnetQueue.AquireServerQueues ( fd ) ;
char SocketOpeningPuke [32] = {0} ;
n = RecvTimeout ( fd, SocketOpeningPuke, sizeof(buffer),
READ_TIMEOUT_IN_SECONDS ) ;someday.
for (;;)
{
n = RecvTimeout ( fd, buffer, sizeof(buffer),
READ_TIMEOUT_IN_SECONDS ) ;
if ( n == 0 )
{
#ifdef TELNET_DISPLAY_ALL
telnet_server_ts_cout << "Telnet closed by remote port."
<< std::endl ;
#endif
break;
}
else if ( n == -1 )
{
#ifdef TELNET_DISPLAY_ALL
telnet_server_ts_cout << "Telnet closed by timeout." <<
std::endl ;
#endif
break;
}
else if ( n == -2 )
{
#ifdef TELNET_DISPLAY_ALL
telnet_server_ts_cout << "Telnet closed by error." <<
std::endl ;
#endif
break;
}
else // Valid data in buffer
TelnetQueue.ServerSend ( fd, buffer, n ) ;
}
#ifdef TELNET_DISPLAY_ALL
telnet_server_ts_cout << "Telnet ReadTask close, Socket " << fd <<
std::endl ;
#endif
if (close (fd) < 0)
telnet_server_ts_cout << "Telnet close Error." << std::endl ;
rtems_status_code sc = rtems_task_delete (RTEMS_SELF);
telnet_server_ts_cout << "Telnet task delete Error." << std::endl ;
}
At 11:13 AM 1/14/2005, Karel Gardas wrote:
>Hello,
>
>before going into deep debugging I would like to ask here if there is
>anybody here using select-based server on RTEMS, where server will not use
>blocking accept, but rather just listen on specified port (socket) and
>pass listening fd to the select and when someone is going to connect, it
>then pass changed fd to the accept. So the sequence of commands done on
>socket is:
>
>socket -> bind -> listen -> select (loop with timeout) -<someone is going
>to open connection>--> accept.
>
>My problem is that select does not report activity on listening socket.
>Anybody has already seen this?
>
>Thanks a lot,
>Karel
>PS: Tested on 4-6-branch with its recommended tool-chain for pc386 BSP
>running inside Qemu emulator
>--
>Karel Gardas kgardas at objectsecurity.com
>ObjectSecurity Ltd. http://www.objectsecurity.com
Steve Holle
Link Communications, Inc.
1035 Cerise Rd.
Billings, MT 59101
sholle at link-comm.com
More information about the users
mailing list