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

Sockets

5.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 tcp\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:

descriptor A descriptor for the accepted socket, if successful.

–1

If not successful.

5-22

Copyright © 1998-2001 ARM Limited. All rights reserved.

ARM DUI 0144B

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. For more details, see t_send() and t_sendto() on page 5-18 and t_recv() and t_recvfrom() on page 5-14.

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 value of -1 and ETIMEDOUT 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 5-10 and t_setsockopt() on page 5-19).

ARM DUI 0144B

Copyright © 1998-2001 ARM Limited. All rights reserved.

5-23

Sockets

5.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(socket).

5-24

Copyright © 1998-2001 ARM Limited. All rights reserved.

ARM DUI 0144B

Chapter 6

Low-overhead UDP Functions

This chapter describes low-overhead UDP functions. The functions described here are low-overhead in that they require little processing time and offer a small memory footprint. It contains the following sections:

UDP functions on page 6-2.

ARM DUI 0144B

Copyright © 1998-2001 ARM Limited. All rights reserved.

6-1