From owner-freebsd-current@FreeBSD.ORG Sun May 20 22:36:58 2007 Return-Path: X-Original-To: freebsd-current@freebsd.org Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 5BEB116A400 for ; Sun, 20 May 2007 22:36:58 +0000 (UTC) (envelope-from coolaz@web.de) Received: from fmmailgate02.web.de (fmmailgate02.web.de [217.72.192.227]) by mx1.freebsd.org (Postfix) with ESMTP id DF5EF13C45B for ; Sun, 20 May 2007 22:36:57 +0000 (UTC) (envelope-from coolaz@web.de) Received: from smtp06.web.de (fmsmtp06.dlan.cinetic.de [172.20.5.172]) by fmmailgate02.web.de (Postfix) with ESMTP id 0A8007FBAA6F for ; Mon, 21 May 2007 00:11:44 +0200 (CEST) Received: from [91.16.240.123] (helo=example.net) by smtp06.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.108 #197) id 1Hptcs-0003l8-00 for freebsd-current@freebsd.org; Mon, 21 May 2007 00:11:43 +0200 Received: by example.net (nbSMTP-1.00) for uid 1001 (using TLSv1/SSLv3 with cipher AES256-SHA (256/256 bits)) coolaz@web.de; Mon, 21 May 2007 00:11:49 +0200 (CEST) Date: Mon, 21 May 2007 00:11:48 +0200 From: Martin Kulas To: freebsd-current@freebsd.org Message-ID: <20070520221148.GA2169@thunderbird.local> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="xHFwDpU9dbj6ez1V" Content-Disposition: inline User-Agent: Mutt/1.4.2.2i X-PGP-Key: http://www.stud.uni-hamburg.de/~kulas/mkulas_pubkey.asc Sender: coolaz@web.de X-Sender: coolaz@web.de X-Provags-ID: V01U2FsdGVkX1/aIVPWYLd0biDI4j613Iy7aF9Ez6lPkZ7zfcru V7OXg7n8SxDIiQ3a2qbW2D0wPuOXOmdiAqeikuw2hJdcd4+Jiv 3YTW7n964= X-Mailman-Approved-At: Sun, 20 May 2007 23:01:16 +0000 Subject: [SCTP] nonblocking write() X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 20 May 2007 22:36:58 -0000 --xHFwDpU9dbj6ez1V Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hello! I hope this is the right mailing list. I am running -CURRENT and=20 I am trying to get an application (thttpd) to use SCTP sockets =20 in one-to-one style. But it does not work. I tracked the problem down to this: The SCTP socket is made non-blocking. Then write() is called. Write() succeeds if we do not write too many bytes; net.inet.sctp.sendspace is the limit for an successfull write(). Is this behaviour intended? Perhaps I am coding something wrong, so here is sample code: $ nl nb.c 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include =09 12 #define DST_IP "127.0.0.1" 13 #define DST_PORT 1234 =09 14 int 15 main() 16 { 17 int s; 18 struct sockaddr_in sa; 19 int ret; 20 int n; 21 char buf[BUFSZ]; 22 int toSend; =09 23 printf("BUFSZ: %u\n", BUFSZ); 24 #ifdef USE_SCTP 25 printf("using sctp\n"); 26 s =3D socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP); 27 #else 28 printf("using tcp\n"); 29 s =3D socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 30 #endif 31 if ( s =3D=3D -1 ) 32 err(1, "socket() failed"); =09 33 #ifdef USE_NONBLOCKING 34 printf("using nonblocking i/o\n"); 35 ret =3D fcntl(s, F_GETFL); 36 if ( ret =3D=3D -1 ) 37 err(1, "fcntl() failed\n"); 38 ret |=3D O_NONBLOCK; 39 ret =3D fcntl(s, F_SETFL, ret); 40 if ( ret =3D=3D -1 ) 41 err(1, "fcntl() failed\n"); 42 #endif =09 43 bzero(&sa, sizeof(sa)); 44 sa.sin_family =3D AF_INET; 45 sa.sin_port =3D htons(DST_PORT); 46 n =3D inet_pton(AF_INET, DST_IP, &sa.sin_addr); 47 if ( n !=3D 1 ) 48 err(1, "inet_pton() failed"); =09 49 ret =3D connect(s, (struct sockaddr *) &sa, sizeof(sa)); 50 if ( ret =3D=3D -1 ) 51 err(1, "connect() failed"); 52 memset(buf, 'a', BUFSZ); =09 53 #ifdef USE_WRITE 54 printf("using write() i/o\n"); 55 toSend =3D BUFSZ; 56 while ( toSend > 0 ) { 57 n =3D write(s, buf, toSend); 58 if ( n > 0 ) { 59 /* OK */ 60 printf("%d bytes send\n", n); 61 toSend -=3D n; 62 } else if ( n =3D=3D 0 ) { 63 err(1, "write() EOF (0 bytes written)\n"); 64 } else { 65 printf("n: %d: %s\n", n, strerror(errno)); 66 sleep(1); 67 } 68 } 69 #endif =09 70 return 0; 71 } $ cc -Wall -DUSE_SCTP -DUSE_WRITE -DUSE_NONBLOCKING -DBUFSZ=3D30000 -o nb n= b.c=20 $ ./nb = =20 BUFSZ: 30000 using sctp using nonblocking i/o using write() i/o 30000 bytes send $ cc -Wall -DUSE_SCTP -DUSE_WRITE -DUSE_NONBLOCKING -DBUFSZ=3D300000 -o nb = nb.c $ ./nb = =20 BUFSZ: 300000 using sctp using nonblocking i/o using write() i/o n: -1: Resource temporarily unavailable n: -1: Resource temporarily unavailable n: -1: Resource temporarily unavailable n: -1: Resource temporarily unavailable n: -1: Resource temporarily unavailable n: -1: Resource temporarily unavailable ^C I googled a bit but I do not get any answer if this behaviour is correct=20 for non-blocking SCTP socket in one-to-one style. Thanks in advance, Martin --=20 PGP Key: http://www.stud.uni-hamburg.de/~kulas/mkulas_pubkey.asc --xHFwDpU9dbj6ez1V Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.3 (FreeBSD) iD8DBQFGUMeju1jKg1agQ1oRAqLsAKDcUizqObwfhip1yWOJMgAVZpt/LACfbuav xo771wg2rDc29ByHb38dvro= =w1aG -----END PGP SIGNATURE----- --xHFwDpU9dbj6ez1V--