tport.c File Reference


Detailed Description

Transport interface implementation.

See tport.docs for more detailed description of tport interface.

Author:
Pekka Pessi <Pekka.Pessi@nokia-email.address.hidden>

Ismo Puustinen <Ismo.H.Puustinen@nokia-email.address.hidden>

Tat Chan <Tat.Chan@nokia-email.address.hidden>

Kai Vehmanen <kai.vehmanen@nokia-email.address.hidden>

Martti Mela <Martti.Mela@nokia-email.address.hidden>

Date:
Created: Thu Jul 20 12:54:32 2000 ppessi

#include "config.h"
#include <sofia-sip/string0.h>
#include <sofia-sip/su.h>
#include <sofia-sip/su_errno.h>
#include <sofia-sip/su_alloc.h>
#include <sofia-sip/su_tagarg.h>
#include <sofia-sip/su_localinfo.h>
#include <sofia-sip/su_wait.h>
#include <sofia-sip/msg.h>
#include <sofia-sip/msg_addr.h>
#include <sofia-sip/hostdomain.h>
#include <stdlib.h>
#include <time.h>
#include <assert.h>
#include <errno.h>
#include <limits.h>
#include "sofia-sip/tport.h"
#include "sofia-sip/su_uniqueid.h"
#include <sofia-sip/rbtree.h>
#include "tport_internal.h"

Include dependency graph for tport.c:

Enumerations

enum  { THRP_PENDING }

Functions

int tport_is_master (tport_t const *self)
 Return true if transport is master.
int tport_is_primary (tport_t const *self)
 Return true if transport is primary.
int tport_is_secondary (tport_t const *self)
 Return true if transport is secondary.
int tport_is_registered (tport_t const *self)
 Test if transport has been registered to su_root_t.
int tport_is_stream (tport_t const *self)
 Return true if transport is a stream (no message boundaries).
int tport_is_dgram (tport_t const *self)
 Return true if transport is dgram-based.
int tport_is_udp (tport_t const *self)
 Test if transport is udp.
int tport_is_tcp (tport_t const *self)
 Test if transport is tcp.
int tport_is_reliable (tport_t const *self)
 Return true if transport is reliable, false otherwise.
int tport_is_public (tport_t const *self)
 Return nonzero if transport is public.
int tport_has_ip4 (tport_t const *self)
 Return true if transport supports IPv4.
int tport_has_tls (tport_t const *self)
 Test if transport has TLS.
int tport_is_updating (tport_t const *self)
 Return true if transport is being updated.
int tport_is_closed (tport_t const *self)
 Test if transport has been closed (added to 1.12.4 ).
int tport_is_shutdown (tport_t const *self)
 Test if transport has been shut down (added to 1.12.4 ).
int tport_is_bound (tport_t const *self)
 Test if transport is bound.
int tport_is_connected (tport_t const *self)
 Test if transport is connected.
int tport_is_clear_to_send (tport_t const *self)
 Test if transport can be used to send message.
unsigned tport_mtu (tport_t const *self)
 MTU for transport.
void tport_set_tos (su_socket_t socket, su_addrinfo_t *ai, int tos)
 Set IP TOS for socket.
int tport_getaddrinfo (char const *node, char const *service, su_addrinfo_t const *hints, su_addrinfo_t **res)
 Translate address and service.
static int tport_bind_server (tport_master_t *mr, tp_name_t const *tpn, char const *const transports[], enum tport_via public, tagi_t *tags)
 Bind primary transport objects used by a server application.
static int tport_setname (tport_t *self, char const *protoname, su_addrinfo_t const *ai, char const *canon)
 Set transport object name.
static int tport_wakeup_pri (su_root_magic_t *m, su_wait_t *w, tport_t *self)
 Process events for primary socket.
static int tport_wakeup (su_root_magic_t *magic, su_wait_t *w, tport_t *self)
 Process events for connected socket.
static int tport_connected (su_root_magic_t *magic, su_wait_t *w, tport_t *self)
 Process events for socket waiting to be connected.
static int tport_pending_error (tport_t *self, su_sockaddr_t const *dst, int error)
 Report error to pending messages with destination.
static int tport_pending_errmsg (tport_t *self, msg_t *msg, int error)
 Report error via pending message.
tport_t * tport_by_addrinfo (tport_primary_t const *pri, su_addrinfo_t const *ai, tp_name_t const *tpn)
 Get transport from primary by addrinfo.
void tport_peer_address (tport_t *self, msg_t *msg)
 Copy peer address to msg.
tport_t * tport_tcreate (tp_stack_t *stack, tp_stack_class_t const *tpac, su_root_t *root, tag_type_t tag, tag_value_t value,...)
 Create first primary transport.
void tport_destroy (tport_t *self)
 Destroy transport(s).
void tport_has_been_updated (tport_t *self)
 Indicate stack that a transport has been updated.
tport_t * tport_alloc_secondary (tport_primary_t *pri, int socket, int accepted, char const **return_reason)
 Allocate a secondary transport.
tport_t * tport_base_connect (tport_primary_t *pri, su_addrinfo_t *ai, su_addrinfo_t *real_ai, tp_name_t const *tpn)
 Create a connected transport object with socket.
void tport_zap_secondary (tport_t *self)
 Destroy a secondary transport.
tport_t * tport_ref (tport_t *tp)
 Create a new reference to a transport object.
void tport_unref (tport_t *tp)
 Destroy reference to a transport object.
tport_t * tport_incref (tport_t *tp)
 Create a new transport reference.
void tport_decref (tport_t **ttp)
 Destroy a transport reference.
int tport_get_params (tport_t const *self, tag_type_t tag, tag_value_t value,...)
 Get transport parameters.
int tport_set_params (tport_t *self, tag_type_t tag, tag_value_t value,...)
 Set transport parameters.
int tport_register_type (tport_vtable_t const *vtp)
 Register new transport vtable.
tport_vtable_t const * tport_vtable_by_name (char const *protoname, enum tport_via public)
 Get a vtable for given protocol.
int tport_tbind (tport_t *self, tp_name_t const *tpn, char const *const transports[], tag_type_t tag, tag_value_t value,...)
 Bind transports to network.
void tport_close (tport_t *self)
 Close a transport.
int tport_shutdown (tport_t *self, int how)
 Shutdown a transport connection.
int tport_flush (tport_t *tp)
 Flush idle connections.
int tport_convert_addr (su_home_t *home, tp_name_t *tpn, char const *protoname, char const *canon, su_sockaddr_t const *su)
 Convert a socket address to a transport name.
void tport_error_report (tport_t *self, int errcode, su_sockaddr_t const *addr)
 Process errors from transport.
int tport_accept (tport_primary_t *pri, int events)
 Accept a new connection.
msg_ttport_msg_alloc (tport_t const *self, usize_t size)
 Allocate a new message object.
int tport_stall (tport_t *self)
 Stop reading from socket until tport_continue() is called.
int tport_continue (tport_t *self)
 Continue reading from socket.
void tport_hup_event (tport_t *self)
 Process "hangup" event.
int tport_recv_data (tport_t *self)
 Receive data available on the socket.
void tport_recv_event (tport_t *self)
 Process "ready to receive" event.
void tport_deliver (tport_t *self, msg_t *msg, msg_t *next, tport_compressor_t *sc, su_time_t now)
 Deliver message to the protocol stack.
void tport_base_deliver (tport_t *self, msg_t *msg, su_time_t now)
 Pass message to the protocol stack.
tport_t * tport_delivered_by (tport_t const *tp, msg_t const *msg)
 Return source transport object for delivered message.
int tport_delivered_from (tport_t *tp, msg_t const *msg, tp_name_t name[1])
 Return source transport name for delivered message.
int tport_delivered_with_comp (tport_t *tp, msg_t const *msg, tport_compressor_t **return_compressor)
 Get compressor context with which the request was delivered.
ssize_t tport_recv_iovec (tport_t const *self, msg_t **in_out_msg, msg_iovec_t iovec[msg_n_fragments], size_t N, int exact)
 Allocate message for N bytes, return message buffer as a iovec.
tport_t * tport_tsend (tport_t *self, msg_t *msg, tp_name_t const *_tpn, tag_type_t tag, tag_value_t value,...)
 Send a message using transport.
int tport_send_msg (tport_t *self, msg_t *msg, tp_name_t const *tpn, struct sigcomp_compartment *cc)
 Send a message.
int tport_tqueue (tport_t *self, msg_t *msg, tag_type_t tag, tag_value_t value,...)
 Queue a message to transport.
isize_t tport_queuelen (tport_t const *self)
 Return number of queued messages.
int tport_tqsend (tport_t *self, msg_t *msg, msg_t *next, tag_type_t tag, tag_value_t value,...)
 Send a queued message (and queue another, if required).
void tport_send_event (tport_t *self)
 Send event.
int tport_error_event (tport_t *self)
 Process error event.
int tport_pend (tport_t *self, msg_t *msg, tport_pending_error_f *callback, tp_client_t *client)
 Mark message as waiting for a response.
int tport_release (tport_t *self, int pendd, msg_t *msg, msg_t *reply, tp_client_t *client, int still_pending)
 Do not wait for response anymore.
void tport_set_magic (tport_t *self, tp_magic_t *magic)
 Set transport magic.
tp_magic_ttport_magic (tport_t const *self)
 Get transport magic.
tport_t * tport_parent (tport_t const *self)
 Get primary transport (or self, if already parent).
tport_t * tport_primaries (tport_t const *self)
 Get primary transports.
tport_t * tport_next (tport_t const *self)
 Get next transport.
tport_t * tport_secondary (tport_t const *self)
 Get secondary transports.
su_addrinfo_t const * tport_get_address (tport_t const *self)
 Get transport address list.
tp_name_t const * tport_name (tport_t const *self)
 Get transport name.
char const * tport_ident (tport_t const *self)
 Get transport ident.
tport_t * tport_by_protocol (tport_t const *self, char const *proto)
 Get a protocol corresponding to the protocol name.
tport_t * tport_primary_by_name (tport_t const *tp, tp_name_t const *tpn)
 Get transport by interface identifier and protocol name.
tport_t * tport_by_name (tport_t const *self, tp_name_t const *tpn)
 Get a transport corresponding to the name.
int tport_name_by_url (su_home_t *home, tp_name_t *tpn, url_string_t const *us)
 Create a transport name corresponding to the URL.
int tport_name_is_resolved (tp_name_t const *tpn)
 Check if transport named is already resolved.
int tport_name_dup (su_home_t *home, tp_name_t *dst, tp_name_t const *src)
 Duplicate a transport name.
char * tport_hostport (char buf[], isize_t bufsize, su_sockaddr_t const *su, int with_port_and_brackets)
 Print host and port separated with ':' to a string.


Enumeration Type Documentation

anonymous enum

Enumerator:
THRP_PENDING  Default per-thread read queue length.


Function Documentation

int tport_accept ( tport_primary_t pri,
int  events 
)

Accept a new connection.

The function tport_accept() accepts a new connection and creates a secondary transport object for the new socket.

tport_t* tport_base_connect ( tport_primary_t pri,
su_addrinfo_t *  ai,
su_addrinfo_t *  real_ai,
tp_name_t const *  tpn 
)

Create a connected transport object with socket.

The function tport_connect() creates a secondary transport with a connected socket. It registers the socket with suitable events to the root.

Parameters:
pri primary transport object
ai pointer to addrinfo structure describing socket
real_ai pointer to addrinfo structure describing real target
tpn canonical name of node

void tport_close ( tport_t *  self  ) 

Close a transport.

The function tport_close() closes a socket associated with a transport object.

int tport_convert_addr ( su_home_t *  home,
tp_name_t tpn,
char const *  protoname,
char const *  canon,
su_sockaddr_t const *  su 
)

Convert a socket address to a transport name.

Return values:
0 when successful
-1 upon an error

void tport_decref ( tport_t **  tp  ) 

Destroy a transport reference.

Deprecated:
Use tport_unref().

int tport_error_event ( tport_t *  self  ) 

Process error event.

Return events that can be processed afterwards.

int tport_get_params ( tport_t const *  self,
tag_type_t  tag,
tag_value_t  value,
  ... 
)

Get transport parameters.

Parameters:
self pointer to a transport object
tag,value,... list of tags

int tport_getaddrinfo ( char const *  node,
char const *  service,
su_addrinfo_t const *  hints,
su_addrinfo_t **  res 
)

Translate address and service.

This is a getaddrinfo() supporting multiple hints in a list.

tport_t* tport_incref ( tport_t *  tp  ) 

Create a new transport reference.

Deprecated:
Use tport_ref().

int tport_is_clear_to_send ( tport_t const *  self  ) 

Test if transport can be used to send message.

int tport_is_closed ( tport_t const *  self  )  [inline]

Test if transport has been closed (added to 1.12.4 ).

Since:
New in 1.12.4

int tport_is_connected ( tport_t const *  self  ) 

Test if transport is connected.

Since:
New in 1.12.5

int tport_is_public ( tport_t const *  self  ) 

Return nonzero if transport is public.

The return valu is the

See also:
TPTAG_PUBLIC(), enum tport_via.

int tport_is_reliable ( tport_t const *  self  ) 

Return true if transport is reliable, false otherwise.

(Note that this is part of external API).

int tport_is_shutdown ( tport_t const *  self  )  [inline]

Test if transport has been shut down (added to 1.12.4 ).

Since:
New in 1.12.4

int tport_name_dup ( su_home_t *  home,
tp_name_t dst,
tp_name_t const *  src 
)

Duplicate a transport name.

The tport_name_dup() function copies strings belonging to the transport name. It returns the copied strings via the dst transport name structure. The memory block required for copies is allocated from the memory home. Please note that only one memory block is allocated, so the memory can be reclainmed only by deinitializing the memory home itself.

Return values:
0 when successful
-1 upon an error

int tport_pend ( tport_t *  self,
msg_t msg,
tport_pending_error_f callback,
tp_client_t client 
)

Mark message as waiting for a response.

Returns:
Positive integer, or -1 upon an error.

int tport_recv_data ( tport_t *  self  )  [inline]

Receive data available on the socket.

Return values:
-1 error
0 end-of-stream
1 normal receive
2 incomplete recv, recv again
3 STUN keepalive, ignore

void tport_send_event ( tport_t *  self  ) 

Send event.

Process SU_WAIT_OUT event.

int tport_send_msg ( tport_t *  self,
msg_t msg,
tp_name_t const *  tpn,
struct sigcomp_compartment *  cc 
)

Send a message.

Return values:
0 when succesful
-1 upon an error

int tport_set_params ( tport_t *  self,
tag_type_t  tag,
tag_value_t  value,
  ... 
)

Set transport parameters.

Parameters:
self pointer to a transport object
tag,value,... list of tags
Related Tags:
TPTAG_MTU(), TPTAG_QUEUESIZE(), TPTAG_IDLE(), TPTAG_TIMEOUT(), TPTAG_DEBUG_DROP(), TPTAG_THRPSIZE(), TPTAG_THRPRQSIZE(), TPTAG_SIGCOMP_LIFETIME(), TPTAG_CONNECT(), TPTAG_SDWN_ERROR(), TPTAG_REUSE(), TPTAG_STUN_SERVER(), and TPTAG_TOS().

int tport_shutdown ( tport_t *  self,
int  how 
)

Shutdown a transport connection.

The tport_shutdown() shuts down a full-duplex transport connection partially or completely. If how is 0, the further incoming data is shut down. If how is 1, further outgoing data is shut down. If how is 2, both incoming and outgoing traffic is shut down.

int tport_tbind ( tport_t *  self,
tp_name_t const *  tpn,
char const *const   transports[],
tag_type_t  tag,
tag_value_t  value,
  ... 
)

Bind transports to network.

Parameters:
self pointer to a transport object
tpn desired transport address
transports list of protocol names supported by stack
tag,value,... tagged argument list
Related Tags:
TPTAG_SERVER(), TPTAG_PUBLIC(), TPTAG_IDENT(), TPTAG_HTTP_CONNECT(), TPTAG_CERTIFICATE(), TPTAG_TLS_VERSION(), and tags used with tport_set_params(), especially TPTAG_QUEUESIZE().

tport_t* tport_tcreate ( tp_stack_t stack,
tp_stack_class_t const *  tpac,
su_root_t *  root,
tag_type_t  tag,
tag_value_t  value,
  ... 
)

Create first primary transport.

Related Tags:
TPTAG_LOG(), TPTAG_DUMP(), tags used with tport_set_params(), especially TPTAG_QUEUESIZE().

int tport_tqsend ( tport_t *  self,
msg_t msg,
msg_t next,
tag_type_t  tag,
tag_value_t  value,
  ... 
)

Send a queued message (and queue another, if required).

The function tport_tqsend() sends a message to the transport.

Deprecated:
Alternative interface will be provided in near future.

int tport_tqueue ( tport_t *  self,
msg_t msg,
tag_type_t  tag,
tag_value_t  value,
  ... 
)

Queue a message to transport.

The tport_tqueue() function queues a message in the send queue. It is used by an (server) application that is required to send (response) messages in certain order. For example, a HTTP server or proxy may receive multiple requests from a single TCP connection. The server is required to answer to the requests in same order as they are received. The responses are, however, sometimes generated asynchronously, that is, a response to a later request may be ready earlier. For that purpose, the HTTP protocol stack queues an empty response message immediately upon receiving a request. Other messages cannot be sent before the queued one.

The function tport_tqsend() is used to send the completed response message.

Parameters:
self pointer to transport object
msg message to be inserted into queue
tag,value,... tagged argument list
Related Tags:
Currently none.
Return values:
0 when successful
-1 upon an error
Errors:
EINVAL Invalid argument(s).
ENOMEM Memory was exhausted.
ENOBUFS The transport object queue was full.
Deprecated:
Alternative interface will be provided in near future.
See also:
tport_tqsend()

tport_t* tport_tsend ( tport_t *  self,
msg_t msg,
tp_name_t const *  _tpn,
tag_type_t  tag,
tag_value_t  value,
  ... 
)

Send a message using transport.

The function tport_tsend() sends a message using the transport self.

Related Tags:
TPTAG_MTU(), TPTAG_REUSE(), TPTAG_CLOSE_AFTER(), TPTAG_SDWN_AFTER(), TPTAG_FRESH(), TPTAG_COMPARTMENT().


Sofia-SIP 1.12.6work - Copyright (C) 2006 Nokia Corporation. All rights reserved. Licensed under the terms of the GNU Lesser General Public License.