SCTP Discussions

Text archives Help


Re: [SCTP-Discussion] What does ext_sendmsg() return??


Chronological Thread 
  • From: Thomas Dreibholz <dreibh AT exp-math.uni-essen.de>
  • To: "Oon Heok Kee" <oonheokkee78 AT hotmail.com>, discussion AT sctp.de
  • Subject: Re: [SCTP-Discussion] What does ext_sendmsg() return??
  • Date: Thu Sep 5 10:22:01 2002
  • List-id: SCTP Discussions <discussion.sctp.de>
  • Organization: University of Essen, Institute for Experimental Mathematics

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

Am Mittwoch, 4. September 2002 08:00 schrieb Oon Heok Kee:
> Hi,
>
> I would like to ask, what's the value that ext_sendmsg() return when
> it's
> called? If I didn't understand wrongly, it returns the number of bytes that
> it's sending, isn't it? Am I right to assume that if it returns a negative
> value, some error has occurred?

Yes, it returns the number of bytes that it is sending.


> I have attached my code as below, because at the portion where it
> calls
> ext_sendmsg(), it always returns an error saying "send() failed: Cannot
> send after transport endpoint shutdown".
>
> Is it because ext_sendmsg() is trying to send an empty user data
> buffer?
>

No, you are calling ext_sendmsg() twice; the second time after the
association already has been shut down.

do {
...
if((recvMsgSize = ext_recvmsg(clntSocket, msg, 0)) < 0) {
DieWithError("recvmsg() failed");
} else {
echoBuffer[recvMsgSize] = '\0';
printf("%s", echoBuffer);
}

...
ext_sendmsg(...)
...
} while(recvMsgSize > 0);

Now, the following happens: The message is received from the client,
recvMsgSize is its length. The ext_sendmsg() will successfully return the
length. Since recvMsgSize > 0, the loop will be executed again. But now, the
connection has already been shut down by the client. ext_recvmsg() will
return 0 (and not -1), the same as TCP will do. Your "if" construct does not
exit the loop and ext_sendmsg() will be called the second time with a message
size of 0 bytes. This will fail, since the connection is shut down.

Use the following code, and your program works as desired:

recvMsgSize = ext_recvmsg(clntSocket, msg, 0);
if(recvMsgSize < 0) {
DieWithError("recvmsg() failed");
} else if(recvMsgSize == 0) {
puts("Connection shut down by client.");
break;
} else {
echoBuffer[recvMsgSize] = '\0';
printf("%s", echoBuffer);
}


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.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE9dxYm32BbsHYPLWURAjVoAKCqolH5szi/7vXv/bt+l3J/35UWXQCgp9to
GobqZya3mzaHJmnj4YTnr8Q=
=kkgY
-----END PGP SIGNATURE-----




Archive powered by MHonArc 2.6.19+.

Top of page