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

Sockets

9.2.11t_send() and t_sendto()

These functions are used to transmit a message.

Syntax

int t_send(int s, char *msg, int len, int flags)

int t_sendto(int s, char *msg, int len, int flags,

 

struct sockaddr *to)

where:

 

s

is a socket descriptor created with t_socket().

msg

is a pointer to the data to be sent.

len

is the number of bytes to be sent.

flags

are flags which control how the data is to be sent (see below).

to

is the destination to which the data is to be sent.

Return value

Returns one of the following:

number of bytes sent

 

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

The t_send() function can be used only when the socket is in a connected state. The t_sendto() function can be used at any time.

The flags parameter is formed from the bitwise OR of zero or more of the following:

MSG_OOB

Sends out-of-band data. Only SOCK_STREAM sockets support out-of-band data.

9-18

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

ARM DUI 0079B

Sockets

MSG_DONTROUTE

The SO_DONTROUTE option is turned on for the duration of the operation. It is used only by diagnostic or routing programs.

If the socket does not have enough buffer space available to hold the message being sent, the send() function blocks, unless the socket has been placed in nonblocking input/output mode (see t_setsockopt() on page 9-20).

ARM DUI 0079B

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

9-19

Sockets

9.2.12t_setsockopt()

This function sets the options associated with a socket.

Syntax

int t_setsockopt(long socket, int optname, char *optval)

where:

socket is the identifier of the socket to be changed.

optname is the name of the option to be set.

optval is the value the option will be set to. The parameter should be nonzero to enable a boolean option, or zero if the option is to be disabled. Most socket-level options take an int parameter for optval.

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

Options

The following options are available:

SO_BIO This sets the socket to blocking mode. Further operations on the socket are blocked until completion.

SO_BROADCAST

This boolean value requests permission to send broadcast datagrams on the socket. Broadcast was a privileged operation in earlier versions of the system.

SO_DONTROUTE

This boolean value indicates that outgoing messages should bypass the standard routing facilities. Instead, messages are directed to the appropriate network interface according to the network portion of the destination address.

9-20

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

ARM DUI 0079B

Sockets

SO_KEEPALIVE

This boolean value enables the periodic transmission of messages on a connected socket. Should the connected party fail to respond to these messages, the connection is considered broken.

SO_LINGER This option controls the action taken when unsent messages are queued on socket and a t_socketclose() is performed.

If the socket promises reliable delivery of data and SO_LINGER is set, the system will block the process on the t_socketclose() attempt until it is able to transmit the data or until it decides it is unable to deliver the information (a timeout period, termed the linger interval, is specified in the t_setsockopt() call when SO_LINGER is requested).

If SO_LINGER is disabled and a t_socketclose() is issued, the system will process the close in a manner that allows the process to continue as quickly as possible.

SO_LINGER uses a pointer to a struct linger parameter, defined in socket.h, that specifies the desired state of the option and the linger interval.

SO_NBIO This sets the socket to nonblocking mode. If further operations on the socket cannot complete immediately, they will return –1 and set the socket’s errno variable to EWOULDBLOCK.

SO_OOBINLINE

With protocols that support out-of-band data, this boolean option requests that out-of-band data be placed in the normal data input queue as received. It will then be accessible with recv() calls without the

MSG_OOB flag.

SO_REUSEADDR

This boolean value indicates that the rules used in validating addresses supplied in a t_bind() call should allow reuse of local addresses.

SO_SNDBUF and SO_RCVBUF

These are options to adjust the normal buffer sizes allocated for output and input buffers, respectively. The buffer size may be increased for high-volume connections or may be decreased to limit the possible backlog of incoming data. The system places an absolute limit of 16KB on these values.

ARM DUI 0079B

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

9-21