Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  
igtlSocket.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: The OpenIGTLink Library
4 Language: C++
5 Web page: http://openigtlink.org/
6
7 Copyright (c) Insight Software Consortium. All rights reserved.
8
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the above copyright notices for more information.
12
13=========================================================================*/
14/*=========================================================================
15
16 Program: Visualization Toolkit
17 Module: $RCSfile: igtlSocket.h,v $
18
19 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
20 All rights reserved.
21 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
22
23 This software is distributed WITHOUT ANY WARRANTY; without even
24 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
25 PURPOSE. See the above copyright notice for more information.
26
27=========================================================================*/
28
40#ifndef __igtlSocket_h
41#define __igtlSocket_h
42
43#include "igtlObject.h"
44#include "igtlObjectFactory.h"
45#include "igtlMacro.h"
46#include "igtlWin32Header.h"
47
48
49#if defined(_WIN32) && !defined(__CYGWIN__)
50#else
51#include <sys/time.h>
52#endif
53
54
55namespace igtl
56{
57
58class SocketCollection;
59
62{
63 public:
64 typedef Socket Self;
68
71
72public:
73
75 int GetConnected() { return (this->m_SocketDescriptor >=0); }
76
78 void CloseSocket() {
79 this->CloseSocket(this->m_SocketDescriptor);
80 this->m_SocketDescriptor = -1;
81 }
82
87 int Send(const void* data, int length);
88
95 int Receive(void* data, int length, int readFully=1);
96
99 int SetTimeout(int timeout);
100
103 int SetReceiveTimeout(int timeout);
104
107 int SetSendTimeout(int timeout);
108
112
115 int SetSendBlocking(int sw);
116
118 int GetSocketAddressAndPort(std::string& address, int & port);
119
124 int Skip(int length, int skipFully=1);
125
126protected:
129
130 void PrintSelf(std::ostream& os) const;
131
133 igtlGetMacro(SocketDescriptor, int);
134
135 //BTX
136 friend class vtkSocketCollection;
137 //ETX
138
142
144 void CloseSocket(int socketdescriptor);
145
148 int BindSocket(int socketdescriptor, int port);
149
153 int SelectSocket(int socketdescriptor, unsigned long msec);
154
157 int Accept(int socketdescriptor);
158
160 int Listen(int socketdescriptor);
161
163 int Connect(int socketdescriptor, const char* hostname, int port);
164
167 int GetPort(int socketdescriptor);
168
172 static int SelectSockets(const int* sockets_to_select, int size,
173 unsigned long msec, int* selected_index);
174
175private:
176 Socket(const Socket&); // Not implemented.
177 void operator=(const Socket&); // Not implemented.
178
179#if defined(_WIN32) && !defined(__CYGWIN__)
180 DWORD m_SendTimeout;
181 DWORD m_ReceiveTimeout;
182 DWORD m_OrigSendTimeout;
183 DWORD m_OrigReceiveTimeout;
184#else
185 struct timeval m_SendTimeout;
186 struct timeval m_ReceiveTimeout;
187 struct timeval m_OrigSendTimeout;
188 struct timeval m_OrigReceiveTimeout;
189#endif
190 int m_SendTimeoutFlag;
191 int m_ReceiveTimeoutFlag;
192
193};
194
195}
196
197#endif
Base class for most igtl classes.
Definition igtlObject.h:61
Implements transparent reference counting.
class IGTL_EXPORT Socket
Definition igtlSocket.h:62
SmartPointer< const Self > ConstPointer
Definition igtlSocket.h:67
int Listen(int socketdescriptor)
Listen for connections on a socket. Returns 0 on success. -1 on error.
int m_SocketDescriptor
Definition igtlSocket.h:132
int GetPort(int socketdescriptor)
void CloseSocket(int socketdescriptor)
Close the socket.
int CreateSocket()
int SetSendTimeout(int timeout)
int Send(const void *data, int length)
Object Superclass
Definition igtlSocket.h:65
static int SelectSockets(const int *sockets_to_select, int size, unsigned long msec, int *selected_index)
int Connect(int socketdescriptor, const char *hostname, int port)
Connect to a server socket. Returns 0 on success, -1 on error.
int Accept(int socketdescriptor)
int GetConnected()
Check is the socket is alive.
Definition igtlSocket.h:75
Socket Self
Definition igtlSocket.h:64
int BindSocket(int socketdescriptor, int port)
int GetSocketAddressAndPort(std::string &address, int &port)
Get socket address.
SmartPointer< Self > Pointer
Definition igtlSocket.h:66
void CloseSocket()
Close the socket.
Definition igtlSocket.h:78
void PrintSelf(std::ostream &os) const
int SetReceiveTimeout(int timeout)
int Receive(void *data, int length, int readFully=1)
int SetReceiveBlocking(int sw)
igtlGetMacro(SocketDescriptor, int)
int SetTimeout(int timeout)
int Skip(int length, int skipFully=1)
int SetSendBlocking(int sw)
int SelectSocket(int socketdescriptor, unsigned long msec)
#define igtlTypeMacro(thisClass, superclass)
Definition igtlMacro.h:486
#define igtlNewMacro(x)
Definition igtlMacro.h:431
#define IGTLCommon_EXPORT
The "igtl" namespace contains all OpenIGTLink classes. There are several nested namespaces within the...

Generated for OpenIGTLink by Doxygen 1.9.8 written by Dimitri van Heesch, © 1997-2012