From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 In-Reply-To: References: Date: Tue, 11 Jan 2011 14:53:23 +0800 Message-ID: From: Fernan Bolando To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [9fans] ape/socket again non-blocking command succeeds but still blocks Topicbox-Message-UUID: 9449ca32-ead6-11e9-9d60-3106f5b1d025 I need to apologize, my sample code made things more confusing. In unix the code I posted would have raised an error because newsockfs=3Daccept()...would not block and just pass through. The idea is you can loop through accept() and multiplex multiple inputs. but in plan9/ape it works just as how you shown regardless of the fcntl non-block command. so I will not be able to loop through several sockets because it would block. On Tue, Jan 11, 2011 at 2:11 PM, Federico G. Benavento wrote: > isn't this the intended behavior? > > lotte% 8.out 777 > NON BLOCK Succeeded > Here is the message: hola > > from a different window: > > lotte% telnet =A0tcp!localhost!777 > connected to tcp!localhost!777 on /net/tcp/20 > hola > I got your messagelotte% > > On Mon, Jan 10, 2011 at 10:31 PM, Fernan Bolando > wrote: >> Hi all >> >> I am testing the non-block socket of ape/plan9 the code below seems to >> succeed in making a non-block sockets on unix, but not in plan9/ape it >> still blocks with no error from fcntl. >> Is this intended? >> >> >> >> /* A simple server in the internet domain using TCP >> =A0 The port number is passed as an argument */ >> #include >> #include >> #include >> #include >> #include >> >> void error(char *msg) >> { >> =A0 =A0perror(msg); >> =A0 =A0exit(1); >> } >> >> int main(int argc, char *argv[]) >> { >> =A0 =A0 int sockfd, newsockfd, portno, clilen; >> =A0 =A0 char buffer[256]; >> =A0 =A0 struct sockaddr_in serv_addr, cli_addr; >> =A0 =A0 int n, sta, fl; >> =A0 =A0 if (argc < 2) { >> =A0 =A0 =A0 =A0 fprintf(stderr,"ERROR, no port provided\n"); >> =A0 =A0 =A0 =A0 exit(1); >> =A0 =A0 } >> =A0 =A0 sockfd =3D socket(AF_INET, SOCK_STREAM, 0); >> =A0 =A0 if (sockfd < 0) >> =A0 =A0 =A0 =A0error("ERROR opening socket"); >> >> =A0 =A0 printf("NON BLOCK Succeeded\n"); >> =A0 =A0 bzero((char *) &serv_addr, sizeof(serv_addr)); >> =A0 =A0 portno =3D atoi(argv[1]); >> =A0 =A0 serv_addr.sin_family =3D AF_INET; >> =A0 =A0 serv_addr.sin_addr.s_addr =3D INADDR_ANY; >> =A0 =A0 serv_addr.sin_port =3D htons(portno); >> =A0 =A0 if (bind(sockfd, (struct sockaddr *) &serv_addr, >> =A0 =A0 =A0 =A0 =A0 =A0 =A0sizeof(serv_addr)) < 0) >> =A0 =A0 =A0 =A0 =A0 =A0 =A0error("ERROR on binding"); >> =A0 =A0 fl =3D fcntl (sockfd, F_GETFL,0); >> =A0 =A0 sta =3D fcntl (sockfd, F_SETFL, fl | O_NONBLOCK); =A0 =A0 =A0 = =A0 =A0 /* set >> nonblock */ >> =A0 =A0 if (sta =3D=3D -1) >> =A0{ >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 printf(" NON_BLOCK FAILED\n"= ); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return 1; >> =A0 =A0 } >> =A0 =A0 listen(sockfd,5); >> =A0 =A0 clilen =3D sizeof(cli_addr); >> =A0 =A0 newsockfd =3D accept(sockfd, >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (struct sockaddr *) &cli_addr, >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 &clilen); >> =A0 =A0 if (newsockfd < 0) >> =A0 =A0 =A0 =A0 =A0error("ERROR on accept"); >> =A0 =A0 bzero(buffer,256); >> =A0 =A0 n =3D read(newsockfd,buffer,255); >> =A0 =A0 if (n < 0) error("ERROR reading from socket"); >> =A0 =A0 printf("Here is the message: %s\n",buffer); >> =A0 =A0 n =3D write(newsockfd,"I got your message",18); >> =A0 =A0 if (n < 0) error("ERROR writing to socket"); >> =A0 =A0 return 0; >> } >> >> > > > > -- > Federico G. Benavento >