66#if (CISST_OS != CISST_WINDOWS)
67#define INVALID_SOCKET -1
68#define SOCKET_ERROR -1
74#ifdef OSA_SOCKET_WITH_STREAM
78template <
class _element,
class _trait = std::
char_traits<_element> >
79class osaSocketStreambuf:
public std::basic_streambuf<_element, _trait>
83 typedef std::basic_streambuf<_element, _trait> BaseClassType;
85 osaSocketStreambuf(osaSocket * socket):
92 typedef typename std::basic_streambuf<_element, _trait>::int_type int_type;
96 virtual int sync(
void);
100 virtual std::streamsize xsputn(
const _element * s, std::streamsize n);
104 virtual std::streamsize xsgetn(_element * s, std::streamsize n);
111 virtual int_type overflow(int_type c = _trait::eof());
119template <
class _element,
class _trait>
120int osaSocketStreambuf<_element, _trait>::sync(
void)
127template <
class _element,
class _trait>
129osaSocketStreambuf<_element, _trait>::xsputn(
const _element *s, std::streamsize n)
131 return this->Socket->Send(s, n);
135template <
class _element,
class _trait>
137osaSocketStreambuf<_element, _trait>::xsgetn(_element * s, std::streamsize n)
139 return this->Socket->Receive(s, n);
143template <
class _element,
class _trait>
144typename osaSocketStreambuf<_element, _trait>::int_type
145osaSocketStreambuf<_element, _trait>::overflow(int_type c)
148 if (_trait::eq_int_type(_trait::eof(), c))
149 return (_trait::not_eof(c));
150 char cCopy = _trait::to_char_type(c);
151 return this->Socket->Send(&cCopy, 1);
172#ifdef OSA_SOCKET_WITH_STREAM
173,
public std::iostream
178 enum { INTERNALS_SIZE = 16 };
179 char Internals[INTERNALS_SIZE];
183 static unsigned int SizeOfInternals(
void);
185#ifdef OSA_SOCKET_WITH_STREAM
186 osaSocketStreambuf<char> Streambuf;
251 bool Connect(
const std::string & host,
unsigned short port);
268 int Send(
const char * bufsend,
unsigned int msglen,
double timeoutSec = 0.0 );
274 int Send(
const std::string & bufsend,
double timeoutSec = 0.0 );
285 int SendAsPackets(
const char * bufsend,
unsigned int msglen,
unsigned int packetSize,
double timeoutSec = 0.0);
297 int SendAsPackets(
const std::string & bufsend,
unsigned int packetSize,
double timeoutSec = 0.0);
305 int Receive(
char * bufrecv,
unsigned int maxlen,
double timeoutSec = 0.0);
325 double timeoutStartSec = 0.0,
double timeoutNextSec = 0.0);
335#ifdef OSA_SOCKET_WITH_STREAM
337 virtual std::basic_streambuf<char> * rdbuf(
void) {
351 unsigned long GetIP(
const std::string & host)
const;
Base class for high level objects.
Definition cmnGenericObject.h:53
Definition osaSocket.h:175
bool Connect(const std::string &host, unsigned short port)
Connect to the server; required for TCP sockets; includes call to SetDestination().
bool Connect(void)
Connect to the server; required for TCP sockets and should be used after SetDestination().
bool GetDestination(osaIPandPort &ip_port) const
Get the destination address for UDP or TCP socket. This is particularly useful for programs using UDP...
static int GetLocalhostIP(std::vector< std::string > &IPaddress)
Retrieve IP address of the localhost as string from each network interface (which may be more than tw...
void SetDestination(const std::string &host, unsigned short port)
Set the destination address for UDP or TCP socket.
static std::string GetLocalhostIP(void)
int SendAsPackets(const char *bufsend, unsigned int msglen, unsigned int packetSize, double timeoutSec=0.0)
Send a byte array via the socket, possibly in multiple packets based on the specified maximum packet_...
int Receive(char *bufrecv, unsigned int maxlen, double timeoutSec=0.0)
Receive a byte array via the socket.
bool GetDestination(std::string &host, unsigned short &port) const
Get the destination address for UDP or TCP socket. This is particularly useful for programs using UDP...
~osaSocket(void)
Destructor.
bool Connect(const osaIPandPort &ip_port)
Connect to the server; required for TCP sockets; includes call to SetDestination().
osaSocket(SocketTypes type=TCP)
Default constructor.
int SocketFD
Definition osaSocket.h:354
bool Connected
Definition osaSocket.h:355
unsigned long GetIP(const std::string &host) const
int GetIdentifier(void) const
Definition osaSocket.h:199
friend class osaSocketServer
Definition osaSocket.h:357
int Send(const char *bufsend, unsigned int msglen, double timeoutSec=0.0)
Send a byte array via the socket.
bool AssignPort(unsigned short port)
Sets the port of a UDP server.
int SendAsPackets(const std::string &bufsend, unsigned int packetSize, double timeoutSec=0.0)
Send a string via the socket, possibly in multiple packets based on the specified maximum packet_size...
void SetDestination(const osaIPandPort &ip_port)
Set the destination address for UDP or TCP socket.
SocketTypes SocketType
Definition osaSocket.h:353
bool Close(void)
Close the socket.
osaSocket(void *socketFDPtr)
osaSocketServer constructor (for use by osaSocketServer)
SocketTypes
Definition osaSocket.h:190
@ TCP
Definition osaSocket.h:190
@ UDP
Definition osaSocket.h:190
int Send(const std::string &bufsend, double timeoutSec=0.0)
Send a string via the socket.
int ReceiveAsPackets(std::string &bufrecv, char *packetBuffer, unsigned int packetSize, double timeoutStartSec=0.0, double timeoutNextSec=0.0)
Receive a string via the socket, possibly in multiple packets. This method can be used with both UDP ...
Assert macros definitions.
#define CMN_ASSERT(expr)
Definition cmnAssert.h:97
#define CMN_DECLARE_SERVICES_INSTANTIATION(className)
Definition cmnClassRegisterMacros.h:199
const int CMN_NO_DYNAMIC_CREATION
Definition cmnClassRegisterMacros.h:325
#define CISST_EXPORT
Definition cmnExportMacros.h:50
Defines cmnGenericObject.
#define CMN_LOG_ALLOW_DEFAULT
Definition cmnLogLoD.h:76
Declaration of cmnLogger amd macros for human readable logging.
Portability across compilers and operating systems tools.
Macros to export the symbols of cisstOSAbstraction (in a Dll).
Definition osaSocket.h:156
osaIPandPort()
Definition osaSocket.h:160
osaIPandPort(const std::string &ip, short port)
Definition osaSocket.h:161
std::string IP
Definition osaSocket.h:157
~osaIPandPort()
Definition osaSocket.h:162
unsigned short Port
Definition osaSocket.h:158
bool operator==(const vctDynamicConstMatrixBase< __matrixOwnerType, _elementType > &otherMatrix) const
Definition vctDynamicConstMatrixBase.h:715
bool operator!=(const vctDynamicConstMatrixBase< __matrixOwnerType, _elementType > &otherMatrix) const
Definition vctDynamicConstMatrixBase.h:743