Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
(ARM).Porting TCP-IP programmer's guide.Ver 1.4.pdf
Скачиваний:
31
Добавлен:
23.08.2013
Размер:
2.79 Mб
Скачать

Sockets

9.2Socket API reference

This section contains an alphabetical list of the functions supported by ARM TCP/IP. The functions are as follows:

t_accept() on page 9-4

t_bind() on page 9-5

t_connect() on page 9-6

t_errno() on page 9-7

t_getpeername() on page 9-8

t_getsockname() on page 9-9

t_getsockopt() on page 9-10

t_listen() on page 9-13

t_recv() and t_recvfrom() on page 9-14

t_select() on page 9-16

t_send() and t_sendto() on page 9-18

t_setsockopt() on page 9-20

t_shutdown() on page 9-22

t_socket() on page 9-23

t_socketclose() on page 9-25.

ARM DUI 0079B

Copyright © 1998 and 1999 ARM Limited. All rights reserved.

9-3

Sockets

9.2.1t_accept()

This function is used to accept a connection from a remote host.

Syntax

long t_accept(long socket, struct sockaddr *addr)

where:

 

socket

is created with t_socket(), bound to an address with t_bind(), and

 

is waiting for connections after a t_listen().

addr

contains the IP address and port number of the connecting entity, as

 

known to the communications layer, when t_accept() returns.

Return value

Returns one of the following:

a descriptor for the accepted socket

 

if successful.

–1

if not successful. On failure, the t_accept() function will set an

 

internal socket variable, errno, to one of the errors listed in ipport.h.

 

The value of errno can be retrieved by a call to t_errno().

Usage

The t_accept() function is used with connection-based socket types, currently with

SOCK_STREAM.

This function extracts the first connection on the queue of pending connections, creates a new socket with the same properties as socket, and allocates a new socket descriptor for the socket.

If no pending connections are present on the queue and the socket is not marked as nonblocking, t_accept() blocks the caller until a connection is present. If the socket is marked as nonblocking and no pending connections are present on the queue, t_accept() returns an error.

The accepted socket is used to read data to and write data from the socket that connected to this one. It is not used to accept more connections. The original socket, socket, remains open for accepting further connections.

It is possible to t_select() a socket for the purposes of doing a t_accept() by selecting it for read.

9-4

Copyright © 1998 and 1999 ARM Limited. All rights reserved.

ARM DUI 0079B

Sockets

9.2.2t_bind()

This function assigns a name to an unnamed socket. When a socket is created with t_socket(), it exists in a name space (address family) but has no name assigned.

Syntax

int t_bind(long socket, struct sockaddr *name)

where:

socket is the identifier of the unnamed socket to be bound.

name

is the IP address and port number to be assigned to socket.

Return value

Returns one of the following:

0

if successful.

–1

if not successful. The internal socket variable errno is set to one of the

 

errors listed in ipport.h. The value of errno can be retrieved by a call

 

to t_errno().

ARM DUI 0079B

Copyright © 1998 and 1999 ARM Limited. All rights reserved.

9-5

Sockets

9.2.3t_connect()

This function creates a socket connection.

Syntax

extern int t_connect(long socket, struct sockaddr *name)

where:

 

socket

is created by t_socket(). It is bound to an IP address and port number

 

using t_bind().

 

If the type, as determined when the socket was created using

 

t_socket(), is SOCK_DGRAM, t_connect() specifies the peer with

 

which the socket is to be associated. This is the address to which

 

datagrams are sent and is the only address from which datagrams are

 

received.

 

If the type is SOCK_STREAM, t_connect() attempts to make a

 

connection to another socket.

name

is an address in the communications space of the remote socket. Each

 

communications space interprets the name parameter in its own way.

Return value

Returns one of the following:

0

if successful.

–1

if not successful. The internal socket variable errno is set to one of the

 

errors listed in ipport.h. The value of errno can be retrieved by a call

 

to t_errno().

Usage

Generally, SOCK_STREAM sockets can successfully use t_connect() only once. SOCK_DGRAM sockets can use t_connect() multiple times to change their association. Datagram sockets may dissolve the association by connecting to an invalid address, such as a null address.

9-6

Copyright © 1998 and 1999 ARM Limited. All rights reserved.

ARM DUI 0079B