• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Select Problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Select Problem


  • Subject: Select Problem
  • From: Dario <email@hidden>
  • Date: Mon, 16 Feb 2004 17:13:29 +0100

I have some problem using select, i can't accept any connection.
this is the test code I have used to understand the problem.
with this it will always wait and never unblocks. what is wrong ?

#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/select.h>
#include <errno.h>
#include <fcntl.h>

int main() {
struct sockaddr_in address;
address.sin_addr.s_addr = 0x00000000;
address.sin_port = 3128;
address.sin_family = AF_INET;

int sock = socket( AF_INET, SOCK_STREAM, 0);

// create socket
printf("socket:%d\n",socket,errno);
if( sock == -1 ) {
printf("can't create socket\n");
return -1;
}

// bind
if( bind(sock,&address,sizeof(address)) != 0 ) {
printf("can't bind");
reutrn -1:
};
if( listen(sock,100) != 0 ) {
printf("can't listen");
reutrn -1:
};

// non blocking flag
if( fcntl(sock,F_SETFD,O_NONBLOCK) == -1 ) {
printf("Can't setup socket for non blocking operation\n");
return -1;
}

fd_set rset;
FD_SET(sock,&rset);
int ret;

while( 1 ) {
ret = select(1,&rset,NULL,NULL,NULL);
printf("ret:%d\n",ret);
printf("set:%d\n",FD_ISSET(sock,&rset));
}

return 0;
}
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Select Problem
      • From: Jens Bauer <email@hidden>
  • Prev by Date: Trying to make a simple xinetd app run
  • Next by Date: Re: Select Problem
  • Previous by thread: Trying to make a simple xinetd app run
  • Next by thread: Re: Select Problem
  • Index(es):
    • Date
    • Thread