This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Problems with accept() not awakening upon connection
- From: Øyvind Harboe <oyvind dot harboe at zylin dot com>
- To: ecos-discuss at sources dot redhat dot com
- Date: Tue, 20 Apr 2004 17:22:53 +0200
- Subject: [ECOS] Problems with accept() not awakening upon connection
- Organization: Zylin AS
Currently I'm trying to debug a echo.c app using sockets.
This is with bsd_tcpip and PPP.
If anyone has any insights to offer, it would be most appreciated.
- It works fine when I compile and run it as a CygWin app, so I believe
the echo.c is using the sockets API correctly.
- When I run the same code under eCos, accept() does not return until I
kill the telnet app which is trying to connect. At that point the eCos
app receives all the data I typed into the telnet console. It appears
as if accept() simply isn't being awaken upon the connection.
- as an orthogonal test, the code below isn't awoken upon a connection
either. Placed just before accept() in echo.c. (Again works when I run
the same test as a CygWin app).
fd_set in_fds;
// Wait for a connection on either of the ports
FD_ZERO(&in_fds);
FD_SET(sd, &in_fds);
// not awoken until connecting telnet application is terminated
select(sd+1, &in_fds, 0, 0, 0);
--
Øyvind Harboe
http://www.zylin.com
#include <netdb.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <time.h>
#include <signal.h>
#include <string.h>
int main()
{
int err;
int sd, sd_current;
struct sockaddr_in sin;
struct sockaddr_in pin;
/* get an internet domain socket */
if ((sd = socket(AF_INET, SOCK_STREAM, 0)) != -1)
{
/* complete the socket structure */
memset(&sin, 0, sizeof(sin));
// sin.sin_len = sizeof(sin);
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = INADDR_ANY;
sin.sin_port = htons(23);
/* bind the socket to the port number */
if (bind(sd, (struct sockaddr *) &sin, sizeof(sin)) != -1)
{
/* show that we are willing to listen */
if (listen(sd, SOMAXCONN) != -1)
{
/* wait for a client to talk to us */
socklen_t addrlen = sizeof(pin);
if ((sd_current = accept(sd, (struct sockaddr *) &pin, &addrlen)) != -1)
{
for (;;)
{
/* get a message from the client */
char dir[10];
int len;
len=recv(sd_current, dir, sizeof(dir), 0);
if (len==-1)
{
break;
}
/* acknowledge the message, reply w/ the file names */
if (send(sd_current, dir, len, 0) != len)
{
break;
}
}
/* close up both sockets */
close(sd_current);
}
}
}
close(sd);
}
return 0;
}
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss