gtpc1m3mTransmission Control Protocol/Internet Protocol

close -- Shut Down a Socket

Note

This description applies only to sockets. See TPF C/C++ Language Support User's Guide for more information about the close function for files.

The close function shuts down a socket and frees resources allocated to that socket.

Format

#include  <socket.h>
int       close(int s);

s
The descriptor of the socket to be closed.

Normal Return

Return code 0 indicates that the function was successful.

Error Return

A return code equal to -1 indicates an error. You can get the specific error code by calling sock_errno. See Appendix C, Socket Error Return Codes for more information about socket errors.

Note:
Unless otherwise stated in the description, the following error codes can be returned for either TCP/IP offload support or TCP/IP native stack support.

Value
Description

SOCNOTSOCK
The s parameter is not a valid socket descriptor.

SOCALREADY
Socket s is marked nonblocking and a previous connection attempt has not been completed. This error code is returned only for TCP/IP offload support.

SOCNOTCONN
The socket is not connected. This error code is returned only for TCP/IP offload support.

SOCNOBUFS
There is not enough buffer space to satisfy request. This error code is returned only for TCP/IP offload support.

EIBMIUCVERR
An error occurred while the message was sent to the offload device. This error code is returned only for TCP/IP offload support.

E1052STATE
The socket was closed because the system was in or cycling down to 1052 state.

EINACT
All offload devices associated with the socket descriptor have been disconnected. The socket is closed. This error code is returned only for TCP/IP offload support.

EINACTWS
An offload device associated with the socket descriptor has been disconnected. The socket is still available. This error code is returned only for TCP/IP offload support.

ESYSTEMERROR
A system error has occurred and closed the socket. This error code is returned only for TCP/IP offload support.

OFFLOADTIMEOUT
A response was not received from the offload device in a specified time period. This error code is returned only for TCP/IP offload support.

Programming Considerations

The close function shuts down the socket associated with socket descriptor s, and frees resources allocated to the socket. If s refers to an open TCP connection, the connection is closed. If a stream socket is closed when there is input data queued, the TCP connection is reset rather than being cleanly closed.

Examples

The following example closes server_sock and exits the ECB.

#include <socket.h>

·
·
·
int rc; int server_sock;
·
·
·
rc = close(server_sock); exit(0);

Related Information