SCTP Discussions

Text archives Help


Re: [SCTP-Discussion] Non-blocking mode for the sctp socket api


Chronological Thread 
  • From: Thomas Dreibholz <dreibh AT exp-math.uni-essen.de>
  • To: Pablo Salinas <pablopesb AT yahoo.com>, discussion AT sctp.de
  • Subject: Re: [SCTP-Discussion] Non-blocking mode for the sctp socket api
  • Date: Fri Jul 25 11:52:02 2003
  • List-id: SCTP Discussions <discussion.sctp.de>
  • Organization: University of Essen, Institute for Experimental Mathematics

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Am Dienstag, 22. Juli 2003 17:37 schrieb Pablo Salinas:
> Hi there,
> I am interested in knowing more about the
> non-blocking mode of the sctp socket api. I need to
> write an application that stablish a sctp association
> with another machine. After that, it must send and
> receive data messages through that sctp association.
> But, the thing is, that it should be able to send and
> receive sctp messages at any given time.
> First question: Does the non-blockin mode work only
> for the UDP-like socket api?
> Or does it work for both, the UDP and TCP styles?

Of couse it works for both, UDP and TCP style.


> Second of all, can anyone send me an example code? It
> doesn't need to be a working code. Just one that will
> give me an idea of the function calls that should be
> made in both sides (the client and server)and the
> order of these function calls.

Just set the flag O_NONBLOCK using ext_fcntl(). The following functions
(copied from the rsplib code) show how to set and unset the non-blocking mode
for a given socket "fd":

/* ###### Set non-blocking mode ########################################## */
bool setBlocking(int fd)
{
int flags = ext_fcntl(fd,F_GETFL,0);
if(flags != -1) {
flags &= ~O_NONBLOCK;
if(ext_fcntl(fd,F_SETFL,flags) == 0) {
return(true);
}
}
return(false);
}


/* ###### Set blocking mode ############################################## */
bool setNonBlocking(int fd)
{
int flags = ext_fcntl(fd,F_GETFL,0);
if(flags != -1) {
flags |= O_NONBLOCK;
if(ext_fcntl(fd,F_SETFL,flags) == 0) {
return(true);
}
}
return(false);
}


For your program, you can probably do the following:
- - Establish SCTP association, socket fd
(Server: ext_bind()/ext_bindx(), ext_listen(), ext_accept()
Client: ext_connect()/ext_connectx()
- - setNonBlocking(fd)
- - ext_select() loop

For examples how to use select, also see the sources of the rsplib
distribution (also under http://www.sctp.de), especially examplepe.c and
examplepu.c. There are also various TCP and UDP examples in the Internet.


Best regards
- --
=======================================================================
Dipl.-Inform. Thomas Dreibholz

University of Essen, Room ES210
Inst. for Experimental Mathematics Ellernstraße 29
Computer Networking Technology Group D-45326 Essen/Germany
- -----------------------------------------------------------------------
E-Mail:
dreibh AT exp-math.uni-essen.de
Homepage: http://www.exp-math.uni-essen.de/~dreibh
=======================================================================
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE/IP3k32BbsHYPLWURAu6EAJwPPmna9UMAxnGPEyDz21jJXmldhACgih46
on3XOMGz6B9DFZexfWDDMqI=
=pbbq
-----END PGP SIGNATURE-----





Archive powered by MHonArc 2.6.19+.

Top of page