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

Sockets

9.2.13t_shutdown()

This function causes all or part of a full duplex connection on the socket associated with socket to be shut down.

Syntax

int t_shutdown(long socket, int how)

where:

 

 

socket

is the connection to be shut down.

how

is the method of shut down, specified as follows:

 

0

further receives are disallowed

 

1

further sends are disallowed

 

2

further sends and receives are disallowed.

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. That value of errno can be retrieved by a call

 

to t_errno().

9-22

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

ARM DUI 0079B

Sockets

9.2.14t_socket()

This function creates an endpoint for communication and returns a descriptor.

Syntax

extern long t_socket (int domain, int type, int protocol)

where:

 

domain

specifies a communications domain within which communication takes

 

place. It selects the protocol family that should be used. The protocol

 

family is typically the same as the address family for the addresses

 

supplied in later operations on the socket. These families are defined in

 

the include file socket.h. The only currently understood format is:

 

PF_INET (ARPA Internet protocols)

type

specifies the semantics of communication. Currently allowed types are:

 

SOCK_STREAM

 

(TCP) Provides sequenced, reliable, two-way

 

connection-based byte streams. An out-of-band data

 

transmission mechanism can be supported.

 

SOCK_DGRAM

 

(UDP) Supports datagrams, connectionless, unreliable

 

messages of a fixed (typically small) maximum length.

protocol

is the protocol to use. It must be set to zero for ARM IP.

Return value

Returns one of the following:

socket descriptor

if successful.

–1

if not successful.

ARM DUI 0079B

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

9-23

Sockets

Usage

SOCK_STREAM sockets are full duplex byte streams, similar to UNIX pipes. A stream socket must be in a connected state before it can send or receive data.

A connection to another socket is created with a t_connect() call. When connected, data can be transferred using t_send() and t_recv(). When a session has been completed, t_socketclose() can be performed. Out-of-band data can also be transmitted and received, as described in the t_send() and t_recv() documentation. See t_send() and t_sendto() on page 9-18 for more details.

The communications protocols used to implement a SOCK_STREAM ensure that data is not lost or duplicated. If a piece of data (for which the peer protocol has buffer space) cannot be transmitted successfully within a reasonable length of time, the connection is considered broken. In this case, calls return with a –1 error and TIMEDOUT is written to the internal variable errno.

The protocols optionally keep sockets warm by forcing transmissions roughly every minute in the absence of other activity. An error is indicated if no response has been received on an otherwise idle connection for an extended period, for example, five minutes.

SOCK_DGRAM sockets allow datagrams to be sent to correspondents named in t_sendto() calls. Datagrams are generally received with t_recvfrom(), which returns the next datagram with its return address.

The operation of sockets is controlled by socket level options. These options are defined in the file socket.h. The t_getsockopt() and t_setsockopt() functions are used to get and set options, respectively (see t_getsockopt() on page 9-10 and t_setsockopt() on page 9-20).

9-24

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

ARM DUI 0079B

Sockets

9.2.15t_socketclose()

This function deletes a descriptor from the reference table. On the close of a socket, associated naming information and queued data are discarded.

Note

This is just close() on traditional sockets systems.

Syntax

int t_socketclose(long socket)

where:

socket is the identifier of the socket to be closed.

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-25

Sockets

9-26

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

ARM DUI 0079B