From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 In-Reply-To: References: Date: Tue, 11 Jan 2011 04:45:12 -0300 Message-ID: From: "Federico G. Benavento" To: fernanbolando@mailc.net, Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [9fans] ape/socket again non-blocking command succeeds but still blocks Topicbox-Message-UUID: 945158b0-ead6-11e9-9d60-3106f5b1d025 it's not fcnlt's fault, ape replaces your sockfd with a pipe when you do listen(), you could call fcntl again after the listen() call... all this is usually combined with select() which in turns does more magic behind the scenes and this behavior isn't exposed. On Tue, Jan 11, 2011 at 3:53 AM, Fernan Bolando w= rote: > 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 =C2=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 >>> =C2=A0 The port number is passed as an argument */ >>> #include >>> #include >>> #include >>> #include >>> #include >>> >>> void error(char *msg) >>> { >>> =C2=A0 =C2=A0perror(msg); >>> =C2=A0 =C2=A0exit(1); >>> } >>> >>> int main(int argc, char *argv[]) >>> { >>> =C2=A0 =C2=A0 int sockfd, newsockfd, portno, clilen; >>> =C2=A0 =C2=A0 char buffer[256]; >>> =C2=A0 =C2=A0 struct sockaddr_in serv_addr, cli_addr; >>> =C2=A0 =C2=A0 int n, sta, fl; >>> =C2=A0 =C2=A0 if (argc < 2) { >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 fprintf(stderr,"ERROR, no port provided\n")= ; >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 exit(1); >>> =C2=A0 =C2=A0 } >>> =C2=A0 =C2=A0 sockfd =3D socket(AF_INET, SOCK_STREAM, 0); >>> =C2=A0 =C2=A0 if (sockfd < 0) >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0error("ERROR opening socket"); >>> >>> =C2=A0 =C2=A0 printf("NON BLOCK Succeeded\n"); >>> =C2=A0 =C2=A0 bzero((char *) &serv_addr, sizeof(serv_addr)); >>> =C2=A0 =C2=A0 portno =3D atoi(argv[1]); >>> =C2=A0 =C2=A0 serv_addr.sin_family =3D AF_INET; >>> =C2=A0 =C2=A0 serv_addr.sin_addr.s_addr =3D INADDR_ANY; >>> =C2=A0 =C2=A0 serv_addr.sin_port =3D htons(portno); >>> =C2=A0 =C2=A0 if (bind(sockfd, (struct sockaddr *) &serv_addr, >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0sizeof(serv_addr)) < 0) >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0error("ERROR on binding= "); >>> =C2=A0 =C2=A0 fl =3D fcntl (sockfd, F_GETFL,0); >>> =C2=A0 =C2=A0 sta =3D fcntl (sockfd, F_SETFL, fl | O_NONBLOCK); =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* set >>> nonblock */ >>> =C2=A0 =C2=A0 if (sta =3D=3D -1) >>> =C2=A0{ >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 printf(" NON_BLOCK FAILED\n"); >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0return 1; >>> =C2=A0 =C2=A0 } >>> =C2=A0 =C2=A0 listen(sockfd,5); >>> =C2=A0 =C2=A0 clilen =3D sizeof(cli_addr); >>> =C2=A0 =C2=A0 newsockfd =3D accept(sockfd, >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (struct sockadd= r *) &cli_addr, >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &clilen); >>> =C2=A0 =C2=A0 if (newsockfd < 0) >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0error("ERROR on accept"); >>> =C2=A0 =C2=A0 bzero(buffer,256); >>> =C2=A0 =C2=A0 n =3D read(newsockfd,buffer,255); >>> =C2=A0 =C2=A0 if (n < 0) error("ERROR reading from socket"); >>> =C2=A0 =C2=A0 printf("Here is the message: %s\n",buffer); >>> =C2=A0 =C2=A0 n =3D write(newsockfd,"I got your message",18); >>> =C2=A0 =C2=A0 if (n < 0) error("ERROR writing to socket"); >>> =C2=A0 =C2=A0 return 0; >>> } >>> >>> >> >> >> >> -- >> Federico G. Benavento >> > > --=20 Federico G. Benavento