InetOSC Class Reference

Abstract OSC over the IP protocol. More...

#include <InetOSC.h>

Inheritance diagram for InetOSC:

[legend]
List of all members.

Public Types

enum  InetOSCAddrType { OSC_IN_IPv4, OSC_IN_IPv6 }
 address family type More...
enum  InetOSCProto { OSC_IN_UDP, OSC_IN_TCP }
 protocol type More...
enum  InetOSCError {
  OSC_IN_SUCCESS = 0x0000, OSC_IN_UNKNOWN = 0x0001, OSC_IN_NOT_IDLE = 0x0002, OSC_IN_WOULDBLOCK = 0x0003,
  OSC_IN_MAXCYCLES = 0x0004, OSC_IN_CLOSED_CONN = 0x0005, OSC_IN_PROTO_UNKNOWN = 0x0100, OSC_IN_ADDR_UNKNOWN = 0x0101,
  OSC_IN_NO_PROCESSOR = 0x0200, OSC_IN_NO_TRANSMGR = 0x0201, OSC_IN_NO_TCPMASTER = 0x0202, OSC_IN_ALREADY_SLAVE = 0x0203,
  OSC_IN_NOT_SLAVE = 0x0204, OSC_IN_GETHOST_ERRNO = 0xC000, OSC_IN_GETPROTO_ERRNO = 0xC001, OSC_IN_SOCKET_ERRNO = 0xC002,
  OSC_IN_SETSOCKOPT_ERRNO = 0xC003, OSC_IN_FCNTL_ERRNO = 0xC004, OSC_IN_BIND_ERRNO = 0xC005, OSC_IN_LISTEN_ERRNO = 0xC006,
  OSC_IN_CONNECT_ERRNO = 0xC007, OSC_IN_SHUTDOWN_ERRNO = 0xC008, OSC_IN_CLOSE_ERRNO = 0xC009, OSC_IN_RECV_ERRNO = 0xC00A,
  OSC_IN_SEND_ERRNO = 0xC00B, OSC_IN_POLL_ERRNO = 0xC00C, OSC_IN_ACCEPT_ERRNO = 0xC00D, OSC_IN_MALLOC_ERRNO = 0xC00E
}
 OSC Inet errors. More...

Public Member Functions

 InetOSC ()
 constructor
virtual ~InetOSC ()
 destructor
const InetOSCError getError () const
 get last error
const int getLastErrno () const
 get last errno code
const InetOSCAddrType getAddrType (void) const
 get address type of this object
void setMaxHandleCycles (const int cycles=-1)
 set maximum number of cycles in handle()
const int getMaxHandleCycles (void) const
 get maximum number of cycles in handle() setting

Static Public Member Functions

static const bool getErrorString (const InetOSCError err, std::string &errString)
 get a string description of an InetOSCError

Protected Member Functions

bool createSocket (int *const sd, const InetOSCProto proto, const InetOSCAddrType addrType)
 create socket
bool bindSocketToAny (int *const sd, const short port, const InetOSCAddrType addrType)
 bind socket to any local address
bool closeSocket (int *const sd, const bool setError=true)
 close socket
bool allocSockAddr (const InetOSCAddrType addrType, struct sockaddr **const addr, socklen_t *const addrlen)
 allocate memory for socket address structs
bool setRemoteAddr (const std::string &host, const short port, const InetOSCAddrType addrType, struct sockaddr *const addr)
 resolve hostname and set remote address struct
bool setRemotePort (const short port, const InetOSCAddrType addrType, struct sockaddr *const addr)
 This is here to support a hack which supports the Max wireTAP stack.
std::string getHostAddress (const InetOSCAddrType addrType, const struct sockaddr *const addr)
 get character string notation out of a network address structure
std::string getHostName (const InetOSCAddrType addrType, const struct sockaddr *const addr)
 reverse lookup hostname out of a network address structure
short getPortNumber (const InetOSCAddrType addrType, const struct sockaddr *const addr)
 get port number out of a network address structure
bool setSocketNonBlock (int *const sd)
 set a socket descriptor non blocking
bool setSocketReuseAddr (int *const sd, bool reuse=true)
 set SO_REUSEADDR option of a socket descriptor

Protected Attributes

InetOSCAddrType _addrType
 address type of this object
InetOSCError _error
 error code of this object
int _lasterrno
 last errno returned by system call
int _socket
 socket descriptor
int _maxHandleCycles
 maximum handle() cycles

Detailed Description

Abstract OSC over the IP protocol.

Author:
Martin Rumori


Member Enumeration Documentation

enum InetOSC::InetOSCAddrType
 

address family type

Enumerator:
OSC_IN_IPv4  internet protocol version 4
OSC_IN_IPv6  internet protocol version 6

enum InetOSC::InetOSCError
 

OSC Inet errors.

This enum is used to sign an error occurred in a OSCInet object

An error usually is signed by a 'false' return value of methods in the OSCInet objects. Use getError() in these objects to get the error code.

Note:
Error codes ending on _ERRNO (and >= 0xC000) sign that an error occured during a system call and that the errno (or h_errno in case of OSC_IN_GETHOST_ERRNO) was saved for further processing. You have to use getLastErrno() to get these saved value and process it by your own, if you need detailed error codes.
See also:
InetTCPMaster, InetTCPSlave, InetUDPMaster
Enumerator:
OSC_IN_SUCCESS  no error, succeeded
OSC_IN_UNKNOWN  unspecified error
OSC_IN_NOT_IDLE  object is not idle
OSC_IN_WOULDBLOCK  operation would block
OSC_IN_MAXCYCLES  _maxHandleCycles reached before EAGAIN (no error)
OSC_IN_CLOSED_CONN  object is not longer connected
OSC_IN_PROTO_UNKNOWN  given protocol unknown
OSC_IN_ADDR_UNKNOWN  given address type unknown
OSC_IN_NO_PROCESSOR  no processor set (e. g. in InetTCPMaster)
OSC_IN_NO_TRANSMGR  no transport manager set (e.g. in InetTCPMaster)
OSC_IN_NO_TCPMASTER  no tcp master set (e.g. in InetTCPSlave)
OSC_IN_ALREADY_SLAVE  slave is already inserted (InetTCPMaster)
OSC_IN_NOT_SLAVE  slave object not found (InetTCPMaster)
OSC_IN_GETHOST_ERRNO  error while gethostbyname()
OSC_IN_GETPROTO_ERRNO  error while getprotobyname()
OSC_IN_SOCKET_ERRNO  error while socket()
OSC_IN_SETSOCKOPT_ERRNO  error while setsockopt()
OSC_IN_FCNTL_ERRNO  error while fcntl()
OSC_IN_BIND_ERRNO  error while bind()
OSC_IN_LISTEN_ERRNO  error while listen()
OSC_IN_CONNECT_ERRNO  error while connect()
OSC_IN_SHUTDOWN_ERRNO  error while shutdown()
OSC_IN_CLOSE_ERRNO  error while close()
OSC_IN_RECV_ERRNO  error while recv() or recvfrom()
OSC_IN_SEND_ERRNO  error while send() or sendto()
OSC_IN_POLL_ERRNO  error while poll()
OSC_IN_ACCEPT_ERRNO  error while accept()
OSC_IN_MALLOC_ERRNO  error while malloc()

enum InetOSC::InetOSCProto
 

protocol type

Enumerator:
OSC_IN_UDP  user datagram protocol
OSC_IN_TCP  transmission control protocol


Member Function Documentation

bool InetOSC::allocSockAddr const InetOSCAddrType  addrType,
struct sockaddr **const   addr,
socklen_t *const   addrlen
[protected]
 

allocate memory for socket address structs

allocates a struct sockaddr_inX according to the given address type

Parameters:
addrType the address type to use
addr pointer to to allocate
addrlen pointer where the address length gets filled in
Returns:
true on success, false on failure

bool InetOSC::bindSocketToAny int *const   sd,
const short  port,
const InetOSCAddrType  addrType
[protected]
 

bind socket to any local address

Parameters:
sd a pointer to the socket descriptor
port the port in network byteorder to bind the socket to
addrType the address type of the socket
Returns:
true on success, false on failure

bool InetOSC::closeSocket int *const   sd,
const bool  setError = true
[protected]
 

close socket

Parameters:
sd a pointer to the socket descriptor
setError false: do not set _error variable this might be useful in the case where you close a socket as reaction on a previous error and you don't want to overwrite the "real" error
Returns:
true on success, false on failure

bool InetOSC::createSocket int *const   sd,
const InetOSCProto  proto,
const InetOSCAddrType  addrType
[protected]
 

create socket

getprotobyname, socket ...

Parameters:
sd a pointer to the socket descriptor
proto the protocol to use for the socket
addrType the address type to use for the socket
Returns:
true on success, false on failure

const InetOSC::InetOSCAddrType InetOSC::getAddrType void   )  const
 

get address type of this object

Returns:
the address type of this object

const InetOSC::InetOSCError InetOSC::getError  )  const
 

get last error

Returns:
the code of the last error occured

const bool InetOSC::getErrorString const InetOSCError  err,
std::string &  errString
[static]
 

get a string description of an InetOSCError

Parameters:
err the error to get the string for
errString a reference to a string to fill with the description
Returns:
true on success, false on unknown error code given

std::string InetOSC::getHostAddress const InetOSCAddrType  addrType,
const struct sockaddr *const   addr
[protected]
 

get character string notation out of a network address structure

Parameters:
addrType the address type to interpret
addr pointer to the sockaddr struct to extract the address from
Returns:
a string containing the character string notation of the address or empty string ("") on error

std::string InetOSC::getHostName const InetOSCAddrType  addrType,
const struct sockaddr *const   addr
[protected]
 

reverse lookup hostname out of a network address structure

Parameters:
addrType the adress type to interpret
addr pointer to the sockadddr struct to extract the address from
Returns:
the hostname looked up or "" if not found
Note:
this method currently only works with IPv4

const int InetOSC::getLastErrno  )  const
 

get last errno code

Returns:
the last errno returned by a system call

const int InetOSC::getMaxHandleCycles void   )  const
 

get maximum number of cycles in handle() setting

See also:
setMaxHandleCycles()
Returns:
the maximum number of handle() cycles set to this object

short InetOSC::getPortNumber const InetOSCAddrType  addrType,
const struct sockaddr *const   addr
[protected]
 

get port number out of a network address structure

Parameters:
addrType the adress type to interpret
addr pointer to the sockadddr struct to extract the port from
Returns:
the port number entry (network byteorder) from the address structure or 0 on error

void InetOSC::setMaxHandleCycles const int  cycles = -1  ) 
 

set maximum number of cycles in handle()

this method determines the maximum number of cycles to read within a handle() call. this is to avoid a "block" of the system if a handle() call never comes back on never-ending receiving of messages. handle() returns in any case if recv got EAGAIN.

for InetUDPMaster this settings correlates directly to the maximum number of received OSC packets within one one handle() call, for InetTCPSlave this number means the the number of receive buffers filled within one handle() call, which may contain more or less OSC packets. for InetTCPMaster, this parameter means the maximum number of pending connections getting accepted within one handle() call.

Parameters:
cycles number of cycles. a negative value means unlimited (read always until EAGAIN), a value of zero means no handle() cycles (receiving disabled)

bool InetOSC::setRemoteAddr const std::string &  host,
const short  port,
const InetOSCAddrType  addrType,
struct sockaddr *const   addr
[protected]
 

resolve hostname and set remote address struct

Parameters:
host the hostname or address to set
port the port number in network byteorder to set
addrType the address type to use
addr pointer to the (allocated) address structure to fill
Returns:
true on success, false on failure

bool InetOSC::setRemotePort const short  port,
const InetOSCAddrType  addrType,
struct sockaddr *const   addr
[protected]
 

This is here to support a hack which supports the Max wireTAP stack.

The Max OSC objects won't let you send and receive UDP from the same socke t * (thus port): so you must receive OSC on a different port than you send on. * But the default behavior when someone sends a subscribe message is to * subscribe the host and port on which the request was sent (so the reply wi ll * go back to the same place.) The hack lets Max people send an integer value * in the subscribe message, which will be used as the port to send future * traffic back to, on the same address. This requires the ability to reset t he * port on a Transmit. But only really a UDPTransmit - except those don't exi st * anymore, they're InetUDPMasters now.

Parameters:
port the port number in network byteorder to set
addrType the address type to use
addr pointer to the (allocated) address structure to change
Returns:
true if ok, false if error

bool InetOSC::setSocketNonBlock int *const   sd  )  [protected]
 

set a socket descriptor non blocking

Parameters:
sd pointer to the socket descriptor
Returns:
true on sucess, false on failure

bool InetOSC::setSocketReuseAddr int *const   sd,
bool  reuse = true
[protected]
 

set SO_REUSEADDR option of a socket descriptor

Parameters:
sd pointer to the socket descriptor
reuse true: set SO_REUSEADDR, false: unset SO_REUSEADDR
Returns:
true on success, false on failure


The documentation for this class was generated from the following files:
Generated on Thu Mar 2 23:51:35 2006 for libOSC++ by  doxygen 1.4.6