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 
55 namespace igtl
56 {
57 
58 class SocketCollection;
59 
62 {
63  public:
64  typedef Socket Self;
65  typedef Object Superclass;
68 
71 
72 public:
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 
85  int Send(const void* data, int length);
86 
93  int Receive(void* data, int length, int readFully=1);
94 
97  int SetTimeout(int timeout);
98 
101  int SetReceiveTimeout(int timeout);
102 
105  int SetSendTimeout(int timeout);
106 
109  int SetReceiveBlocking(int sw);
110 
113  int SetSendBlocking(int sw);
114 
116  int GetSocketAddressAndPort(std::string& address, int & port);
117 
122  int Skip(int length, int skipFully=1);
123 
124 protected:
125  Socket();
126  ~Socket();
127 
128  void PrintSelf(std::ostream& os) const;
129 
131  igtlGetMacro(SocketDescriptor, int);
132 
133  //BTX
134  friend class vtkSocketCollection;
135  //ETX
136 
139  int CreateSocket();
140 
142  void CloseSocket(int socketdescriptor);
143 
146  int BindSocket(int socketdescriptor, int port);
147 
151  int SelectSocket(int socketdescriptor, unsigned long msec);
152 
155  int Accept(int socketdescriptor);
156 
158  int Listen(int socketdescriptor);
159 
161  int Connect(int socketdescriptor, const char* hostname, int port);
162 
165  int GetPort(int socketdescriptor);
166 
170  static int SelectSockets(const int* sockets_to_select, int size,
171  unsigned long msec, int* selected_index);
172 
173 private:
174  Socket(const Socket&); // Not implemented.
175  void operator=(const Socket&); // Not implemented.
176 
177 #if defined(_WIN32) && !defined(__CYGWIN__)
178  DWORD m_SendTimeout;
179  DWORD m_ReceiveTimeout;
180  DWORD m_OrigSendTimeout;
181  DWORD m_OrigReceiveTimeout;
182 #else
183  struct timeval m_SendTimeout;
184  struct timeval m_ReceiveTimeout;
185  struct timeval m_OrigSendTimeout;
186  struct timeval m_OrigReceiveTimeout;
187 #endif
188  int m_SendTimeoutFlag;
189  int m_ReceiveTimeoutFlag;
190 
191 };
192 
193 }
194 
195 #endif
Object Superclass
Definition: igtlSocket.h:65
#define igtlGetMacro(name, type)
Definition: igtlMacro.h:222
#define igtlTypeMacro(thisClass, superclass)
Definition: igtlMacro.h:486
SmartPointer< const Self > ConstPointer
Definition: igtlSocket.h:67
The "igtl" namespace contains all OpenIGTLink classes. There are several nested namespaces within the...
void CloseSocket()
Close the socket.
Definition: igtlSocket.h:78
int m_SocketDescriptor
Definition: igtlSocket.h:130
#define IGTLCommon_EXPORT
SmartPointer< Self > Pointer
Definition: igtlSocket.h:66
class IGTL_EXPORT Socket
Definition: igtlSocket.h:61
Socket Self
Definition: igtlSocket.h:64
#define igtlNewMacro(x)
Definition: igtlMacro.h:431
Base class for most igtl classes.
Definition: igtlObject.h:60

Generated at Tue Aug 4 2015 16:20:53 for OpenIGTLink by doxygen 1.8.9.1 written by Dimitri van Heesch, © 1997-2012