66 #if (CISST_OS != CISST_WINDOWS)
67 #define INVALID_SOCKET -1
68 #define SOCKET_ERROR -1
74 #ifdef OSA_SOCKET_WITH_STREAM
78 template <
class _element,
class _trait = std::
char_traits<_element> >
79 class osaSocketStreambuf:
public std::basic_streambuf<_element, _trait>
83 typedef std::basic_streambuf<_element, _trait> BaseClassType;
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());
119 template <
class _element,
class _trait>
120 int osaSocketStreambuf<_element, _trait>::sync(
void)
127 template <
class _element,
class _trait>
129 osaSocketStreambuf<_element, _trait>::xsputn(
const _element *s, std::streamsize n)
131 return this->Socket->
Send(s, n);
135 template <
class _element,
class _trait>
137 osaSocketStreambuf<_element, _trait>::xsgetn(_element * s, std::streamsize n)
139 return this->Socket->Receive(s, n);
143 template <
class _element,
class _trait>
144 typename osaSocketStreambuf<_element, _trait>::int_type
145 osaSocketStreambuf<_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);
154 #endif // OSA_SOCKET_WITH_STREAM
161 osaIPandPort(
const std::string &ip,
short port) : IP(ip), Port(port) {}
172 #ifdef OSA_SOCKET_WITH_STREAM
173 ,
public std::iostream
174 #endif // OSA_SOCKET_WITH_STREAM
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;
187 #endif // OSA_SOCKET_WITH_STREAM
204 static std::string GetLocalhostIP(
void);
210 static int GetLocalhostIP(std::vector<std::string> & IPaddress);
213 bool AssignPort(
unsigned short port);
218 void SetDestination(
const std::string & host,
unsigned short port);
231 bool GetDestination(std::string & host,
unsigned short &port)
const;
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);
324 int ReceiveAsPackets(std::string & bufrecv,
char *packetBuffer,
unsigned int packetSize,
325 double timeoutStartSec = 0.0,
double timeoutNextSec = 0.0);
333 bool IsConnected(
void);
335 #ifdef OSA_SOCKET_WITH_STREAM
337 virtual std::basic_streambuf<char> * rdbuf(
void) {
340 #endif // OSA_SOCKET_WITH_STREAM
351 unsigned long GetIP(
const std::string & host)
const;
362 #endif // _osaSocket_h
#define CISST_EXPORT
Definition: cmnExportMacros.h:50
Assert macros definitions.
~osaIPandPort()
Definition: osaSocket.h:162
#define CMN_ASSERT(expr)
Definition: cmnAssert.h:90
SocketTypes SocketType
Definition: osaSocket.h:353
Portability across compilers and operating systems tools.
Base class for high level objects.
Definition: cmnGenericObject.h:51
Definition: osaSocketServer.h:52
int SocketFD
Definition: osaSocket.h:354
CMN_DECLARE_SERVICES_INSTANTIATION(osaSocket)
bool Connected
Definition: osaSocket.h:355
Declaration of cmnLogger amd macros for human readable logging.
unsigned short Port
Definition: osaSocket.h:158
Defines cmnGenericObject.
SocketTypes
Definition: osaSocket.h:190
Macros to export the symbols of cisstOSAbstraction (in a Dll).
#define CMN_DECLARE_SERVICES(hasDynamicCreation, lod)
Definition: cmnClassRegisterMacros.h:116
osaIPandPort(const std::string &ip, short port)
Definition: osaSocket.h:161
std::string IP
Definition: osaSocket.h:157
osaIPandPort()
Definition: osaSocket.h:160
Definition: osaSocket.h:156
Definition: osaSocket.h:171
Definition: osaSocket.h:190
int Send(const char *bufsend, unsigned int msglen, double timeoutSec=0.0)
Send a byte array via the socket.
int GetIdentifier(void) const
Definition: osaSocket.h:199
const int CMN_NO_DYNAMIC_CREATION
Definition: cmnClassRegisterMacros.h:328
#define CMN_LOG_ALLOW_DEFAULT
Definition: cmnLogLoD.h:76