1

The client program i have written uses SCTP sockets for communication. I am using sctp_recvmsg to read the data available for a particular user from socket. I have noticed that at times sctp_recvmsg returns 0 value instead of number of bytes read or -1 indicating an error. I have checked my code and the socket from which data is being read is not closed. Can someone throw light on how can such a behavior be seen?

Thanks in Advance.

Regards, Sujay

zx81
  • 41,100
  • 9
  • 89
  • 105
user562082
  • 61
  • 1
  • 8
  • Which OS do you use? Linux, Solaris...Could you provide code? If possible, use tcpdump/snoop to capture the network packages. – Nan Xiao Mar 04 '14 at 01:33

1 Answers1

0

According to this lksctp thread, sctp_recvmsg() returns 0 if the other side closed the connection when you are in a 1-to-1 SCP connection (see here for an explanation of one-to-one and one-to-many connections) - that is, when you create the socket with SOCK_STREAM instead of SOCK_SEQPACKET.

Quoting:

Return values from sctp_sendmsg and sctp_recvmsg are not documented, but I would suppose sctp_sendmsg would return -1 and set errno to ECONNRESET same way as sendmsg does. However, what about sctp_recvnmsg? Plain recvmsg should return 0 if half-connection is closed, but there are no half-connections in SCTP. How does the function behave exactly?

The sctp_recvmsg() will return 0 on termination only on 1-to-1 sockets. However, the above notifications will work on both styles.

nh2
  • 24,526
  • 11
  • 79
  • 128