home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD2.bin
/
bbs
/
comm
/
amitcp-3.0ß2.lha
/
AmiTCP
/
src
/
amitcp
/
api
/
auto_socket.c
< prev
next >
Wrap
Text File
|
1994-02-28
|
46KB
|
1,140 lines
/****** bsdsocket.library/accept ********************************************
*
* NAME
* accept - accept a connection on a socket
*
* SYNOPSIS
* #include <sys/types.h>
* #include <sys/socket.h>
*
* ns = accept(s, addr, addrlen)
* D0 D0 A0 A1
*
* long accept(long, struct sockaddr *, long *);
*
* FUNCTION
* The argument s is a socket that has been created with
* socket(), bound to an address with bind(), and is listen-
* ing for connections after a listen(). accept() extracts the
* first connection on the queue of pending connections,
* creates a new socket with the same properties of s and allo-
* cates a new socket descriptor for the socket. If no pending
* connections are present on the queue, and the socket is not
* marked as non-blocking, accept() blocks the caller until a
* connection is present. If the socket is marked non-blocking
* and no pending connections are present on the queue,
* accept() returns an error as described below. The accepted
* socket is used to read and write data to and from the socket
* which connected to this one; it is not used to accept more
* connections. The original socket s remains open for accept-
* ing further connections.
*
* The argument addr is a result parameter that is filled in
* with the address of the connecting entity, as known to the
* communications layer. The exact format of the addr parame-
* ter is determined by the domain in which the communication
* is occurring. The addrlen is a value-result parameter; it
* should initially contain the amount of space pointed to by
* addr; on return it will contain the actual length (in bytes)
* of the address returned. This call is used with
* connection-based socket types, currently with SOCK_STREAM.
*
* It is possible to select() a socket for the purposes of
* doing an accept() by selecting it for read.
*
* RETURN VALUES
* accept() returns a non-negative descriptor for the accepted
* socket on success. On failure, it returns -1 and sets errno
* to indicate the error.
*
* ERRORS
* EBADF - The descriptor is invalid.
*
* EINTR - The operation was interrupted by a break
* signal.
*
* EOPNOTSUPP - The referenced socket is not of type
* SOCK_STREAM.
*
* EWOULDBLOCK - The socket is marked non-blocking and no con-
* nections are present to be accepted.
*
* SEE ALSO
* bind(), connect(), listen(), select(), SetSocketSignals(),
* socket()
*****************************************************************************
*
*/
/****** bsdsocket.library/bind **********************************************
*
* NAME
* bind - bind a name to a socket
*
* SYNOPSIS
* #include <sys/types.h>
* #include <sys/socket.h>
*
* success = bind(s, name, namelen)
* D0 D0 A0 D1
*
* long bind(long, struct sockaddr *, long);
*
* FUNCTION
* bind() assigns a name to an unnamed socket. When a socket
* is created with socket(2) it exists in a name space (address
* family) but has no name assigned. bind() requests that the
* name pointed to by name be assigned to the socket.
*
* RETURN VALUES
* 0 - on success.
*
* -1 - on failure and sets errno to indicate the error.
*
* ERRORS
* EACCES - The requested address is protected, and
* the current user has inadequate permis-
* sion to access it.
*
* EADDRINUSE - The specified address is already in use.
*
* EADDRNOTAVAIL - The specified address is not available
* from the local machine.
*
* EBADF - s is not a valid descriptor.
*
* EINVAL - namelen is not the size of a valid
* address for the specified address fam-
* ily.
*
* The socket is already bound to an
* address.
*
* SEE ALSO
* connect(), getsockname(), listen(), socket()
*
* NOTES
* The rules used in name binding vary between communication
* domains.
*****************************************************************************
*
*/
/****** bsdsocket.library/CloseSocket ***************************************
*
* NAME
* CloseSocket - delete a socket descriptor
*
* SYNOPSIS
* success = CloseSocket(s)
* D0 D0
*
* long CloseSocket(long);
*
* FUNCTION
* CloseSocket() deletes a descriptor from the library base
* socket reference table. If s is the last reference to the
* underlying object, then the object will be deactivated and
* socket (see socket()), associated naming information and
* queued data are discarded.
*
* All sockets are automatically closed when the socket library
* is closed, but closing sockets as soon as possible is
* recommended to save system resources.
*
* RETURN VALUES
* 0 on success.
*
* -1 on failure and sets errno to indicate the error.
*
* ERRORS
* EBADF - s is not an active socket descriptor.
*
* EINTR - linger on close was interrupted.
* The socket is closed, however.
*
* SEE ALSO
* accept(), SocketBaseTagList(), shutdown(), socket(),
* exec.library/CloseLibrary()
*****************************************************************************
*
*/
/****** bsdsocket.library/connect *******************************************
*
* NAME
* connect - initiate a connection on a socket
*
* SYNOPSIS
* #include <sys/types.h>
* #include <sys/socket.h>
*
* success = connect(s, name, namelen)
* D0 D0 A0 D1
*
* long connect(long, struct sockaddr *, long);
*
* FUNCTION
* The parameter s is a socket. If it is of type SOCK_DGRAM,
* then this call specifies the peer with which the socket is
* to be associated; this address is that to which datagrams
* are to be sent, and the only address from which datagrams
* are to be received. If it is of type SOCK_STREAM, then this
* call attempts to make a connection to another socket. The
* other socket is specified by name which is an address in the
* communications space of the socket. Each communications
* space interprets the name parameter in its own way. Gen-
* erally, stream sockets may successfully connect() only once;
* datagram sockets may use connect() multiple times to change
* their association. Datagram sockets may dissolve the asso-
* ciation by connecting to an invalid address, such as a null
* address.
*
* RETURN VALUES
* 0 on success.
*
* -1 on failure and sets errno to indicate the error.
*
* ERRORS
* EADDRINUSE - The address is already in use.
*
* EADDRNOTAVAIL - The specified address is not available
* on the remote machine.
*
* EAFNOSUPPORT - Addresses in the specified address fam-
* ily cannot be used with this socket.
*
* EALREADY - The socket is non-blocking and a previ-
* ous connection attempt has not yet been
* completed.
*
* EBADF - s is not a valid descriptor.
*
* ECONNREFUSED - The attempt to connect was forcefully
* rejected. The calling program should
* CloseSocket() the socket descriptor, and
*