Re: socket select send
From: Maxim Yegorushkin (maxim.yegorushkin_at_gmail.com)
Date: 07/29/05
- Next message: Doug Freyburger: "Re: How to determine the partition for a file"
- Previous message: Paul Pluzhnikov: "Re: apparent 4 GB memory limit for brk() in solaris 8 on some hardware...?"
- In reply to: Wenfei: "Re: socket select send"
- Next in thread: Wenfei: "Re: socket select send"
- Reply: Wenfei: "Re: socket select send"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 29 Jul 2005 11:05:33 -0700
Wenfei wrote:
> Thanks for your quick reply, Maxim.
>
> >if (FD_ISSET(j, &master)) {
> >// except the listener and ourselves
> > if (j != listener && j != i) {
> I am wondering, besides i and listener, whoelse is in the master set?
There are listening and accepted sockets (i.e. client connections) in
the master set.
> The following is my code( not completed), do you think it is right? if
> not, could you please correct it?
> Thanks,
>
> //for receiving:
> void receiving(){
> ...
> while(1){
> FD_SET(sockfd, &fdwrite);
> FD_SET(sockfd, &fdread);
> listen(sockfd, NET_TCP_MAX_SYN_BACKLOG);
> select(maxfd+1, &fdread, &fdwrite, ...);
> if ( FD_ISSET(sockfd, &readFDList) )
> connectionfd = accept(sockfd, ...);
You should check accept() result because it may fail.
> if (connectionfd > maxfd)
> connectionfd = maxfd;
> FD_SET(connectionfd, &fdread);
> FD_SET(connectionfd, &fdwrite);
As you just set connectionfd it will be processed in the following loop
as ready for read, although it may not.
> // run through the existing connections to recvive
> for( i = 0; i <= maxfd; i++ )
> if ( (FD_ISSET(connectionfd, &fdread)) && (i != sockfd) )
> recv(connectionfd, ...);
> }
> ...
> }
>
> //for sending:
> void sending(){
> ...
> for( i = 0; i <= maxfd; i++ )
> if ( (FD_ISSET(connectionfd, &fdwrite)) && (i != sockfd) )
> send(connectionfd, ...);
> ...
> }
>
> Here fdwrite and connectionfd are global variables.
Man, get yourself a book, they discuss in details all those things.
- Next message: Doug Freyburger: "Re: How to determine the partition for a file"
- Previous message: Paul Pluzhnikov: "Re: apparent 4 GB memory limit for brk() in solaris 8 on some hardware...?"
- In reply to: Wenfei: "Re: socket select send"
- Next in thread: Wenfei: "Re: socket select send"
- Reply: Wenfei: "Re: socket select send"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]