0

I am using a unix socket. When buffer is send to the socket it gives me unknown error 196. Please help on this.

BOOL SendData(int iBuffer) { //Send data over socket int nRet = send(m_listenSock, m_cBuffer, iBuffer, 0); if(SOCKET_ERROR > nRet) { //log the error char temp; int length= sizeof(int); int rc = getsockopt(m_listenSock,SOL_SOCKET,SO_ERROR,&temp,(socklen_t *)&length); //if(rc == 0) { errno = temp; perror("\nError is"); } #ifndef LINUX WSACleanup(); #else close(m_listenSock); #endif printf("\nSend data failed to"); return FALSE; } return TRUE; } 
1
  • 1
    post the code that causes the problem Commented Dec 10, 2009 at 10:58

2 Answers 2

1

If errno is set but the call didn't fail (i.e. it didn't return -1), then errno's value isn't related to the last call you did. You can try clearing first:

errno = 0; 

To be on the safe side. What I'm trying to say is that you can't know that the value of errno is relevant except right after the call that set it. You must check all calls you do that can fail for success/failure.

Sign up to request clarification or add additional context in comments.

Comments

0

To detect an error you SHOULD be checking that send returns -1. I don't know what SOCKET_ERROR is, but if it's -1, then the above code won't work right anyway.

Assuming you do get -1 from send(), then an error code will be in errno. It is not necessary to do a getsockopt to retrieve it.

There is no error code 196, so I'd be deeply suspicious about your error handling.

Also, if send() fails, you should probably not close the socket. You haven't specified either the address family or socket type, but I'm assuming AF_INET and SOCK_DGRAM respectively (i.e. UDP)

1 Comment

SOCKET_ERROR == -1 = true

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.