I mean, When use select() and send() to handle multi connections,
should we use listen and accept also, like select and recv?
Which of the follwoing is correct?
1)
....
FD_SET(sockfd, &fdwrite);
listen(sockfd, NET_TCP_MAX_SYN_BACKLOG);
select(...);
connectionfd = accept(sockfd, ...);
FD_SET(connectionFD, &fdwrite);
if (FD_ISSET(connectionfd, &fdwrite))
send;
OR, 2)
FD_SET(sockfd, &fdwrite);
listen(sockfd, NET_TCP_MAX_SYN_BACKLOG);
select(...);
connectionfd = accept(sockfd, ...);
// run through the existing connections to send
for( i = 0; i <= maxFD; i++ )
if ( (FD_ISSET(connectionfd, &fdwrite)) && (i != sockfd) )
send;
OR , 3)
....
FD_SET(sockfd, &fdwrite);
listen(sockfd, NET_TCP_MAX_SYN_BACKLOG);
select(...);
if (FD_ISSET(sockfd, &fdwrite))
send;
OR , 4)
....
FD_SET(sockfd, &fdwrite);
select(...);
if (FD_ISSET(sockfd, &fdwrite))
send;
Thanks,
Wenfei