Re: socket select send
From: Wenfei (ye_wenfei_at_hotmail.com)
Date: 07/29/05
- Next message: Stefaan A Eeckels: "Re: apparent 4 GB memory limit for brk() in solaris 8 on some hardware...?"
- Previous message: Doug Freyburger: "Re: How to determine the partition for a file"
- In reply to: Maxim Yegorushkin: "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:42:39 -0700
Maxim Yegorushkin wrote:
> 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.
"listener" is the listening socket, and "i" are accepted sockets.
Besides those, anything else?
I mean (j != listener && j != i) will give you no sockets.
>
> > 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.
This is the same logic as your link
http://www.ecst.csuchico.edu/~beej/guide/net/examples/selectserver.c
which set newfd after select() and accept(). It will not be processed
in the following loop until next turn while loop or your for(;;) loop
if you are right.
>
> > // 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.
I did. but they didn't talk about what I am concerned. And also, for
your link
http://www.ecst.csuchico.edu/~beej/guide/net/examples/selectserver.c
I found, it didn't use writefd in select() and didn't check writebility
before send().
Thanks,
- Next message: Stefaan A Eeckels: "Re: apparent 4 GB memory limit for brk() in solaris 8 on some hardware...?"
- Previous message: Doug Freyburger: "Re: How to determine the partition for a file"
- In reply to: Maxim Yegorushkin: "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 ]
Relevant Pages
|