Question about socket
jameszxj
jameszxj at gmail.com
Thu Dec 28 02:47:51 UTC 2017
I use the rtems version on github, and configure it use libbsd network library.
I config rtems file descriptors as 200
#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 200
and run tcp server on the board.
static void vtio_task(rtems_task_argument arg)
{
struct sockaddr_in l_addr;
int addrlen;
int s = socket(AF_INET, SOCK_STREAM, 0);
if (s < 0)
{
printf("creat socket error.\n");
return;
}
memset(&l_addr, 0, sizeof(l_addr));
l_addr.sin_family = AF_INET;
l_addr.sin_port = htons(6789);
l_addr.sin_addr.s_addr = htonl(INADDR_ANY);
int ret = bind(s, (const struct sockaddr *) &l_addr, sizeof(struct sockaddr));
if (ret < 0)
{
printf("bind socket error.\n");
return;
}
ret = listen(s, 5);
if (ret < 0)
{
printf("listen socket error.\n");
return;
}
while(1)
{
struct fd_set read_set;
int sock = accept(s, (struct sockaddr *)&l_addr, (socklen_t *)&addrlen);
printf("new socket %d\n", sock);
while(1)
{
FD_ZERO(&read_set);
FD_SET(sock, &read_set);
ret = select(sock+1, NULL, &read_set, NULL, NULL);
if (ret <= 0)
{
perror("select error");
close(sock);
break;
}
ret = recv(sock, buf, 1024, 0);
if (ret > 0)
{
send(sock, buf, ret, 0);
}
else
{
perror("recv error");
close(sock);
break;
}
}
}
}
I run a test(connect=>write=>disconnect cyclic) from PC, When socket number>=65,the select,send,recv functions returns error. errno message:(select error: Bad file number)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/users/attachments/20171228/996cdbdd/attachment.html>
More information about the users
mailing list