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 
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 
111  int SetReceiveBlocking(int sw);
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 
126 protected:
127  Socket();
128  ~Socket();
129 
130  void PrintSelf(std::ostream& os) const;
131 
133  igtlGetMacro(SocketDescriptor, int);
134 
135  //BTX
136  friend class vtkSocketCollection;
137  //ETX
138 
141  int CreateSocket();
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 
175 private:
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
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:132
#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 Sat Aug 22 2015 03:53:41 for OpenIGTLink by doxygen 1.8.9.1 written by Dimitri van Heesch, © 1997-2012