Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

16.8.2 Closing a Socket

When you have finished using a socket, you can simply close its file descriptor with close; see Opening and Closing Files. If there is still data waiting to be transmitted over the connection, normally close tries to complete this transmission. You can control this behavior using the SO_LINGER socket option to specify a timeout period; see Socket Options.

You can also shut down only reception or transmission on a connection by calling shutdown, which is declared in sys/socket.h.

— Function: int shutdown (int socket, int how)

The shutdown function shuts down the connection of socket socket. The argument how specifies what action to perform:

0
Stop receiving data for this socket. If further data arrives, reject it.
1
Stop trying to transmit data from this socket. Discard any data waiting to be sent. Stop looking for acknowledgement of data already sent; don't retransmit it if it is lost.
2
Stop both reception and transmission.

The return value is 0 on success and -1 on failure. The following errno error conditions are defined for this function:

EBADF
socket is not a valid file descriptor.
ENOTSOCK
socket is not a socket.
ENOTCONN
socket is not connected.


 
 
  Published under the terms of the GNU General Public License Design by Interspire