VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkSocket.h 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00022 #ifndef __vtkSocket_h 00023 #define __vtkSocket_h 00024 00025 #include "vtkObject.h" 00026 00027 class vtkSocketCollection; 00028 class VTK_COMMON_EXPORT vtkSocket : public vtkObject 00029 { 00030 public: 00031 vtkTypeMacro(vtkSocket, vtkObject); 00032 void PrintSelf(ostream& os, vtkIndent indent); 00033 00034 // ----- Status API ---- 00036 int GetConnected() { return (this->SocketDescriptor >=0); } 00037 00039 void CloseSocket(); 00040 00041 // ------ Communication API --- 00044 int Send(const void* data, int length); 00045 00051 int Receive(void* data, int length, int readFully=1); 00052 00054 00056 vtkGetMacro(SocketDescriptor, int); 00058 00060 00062 static int SelectSockets(const int* sockets_to_select, int size, 00063 unsigned long msec, int* selected_index); 00064 protected: 00065 vtkSocket(); 00066 ~vtkSocket(); 00068 00069 int SocketDescriptor; 00070 00071 //BTX 00072 friend class vtkSocketCollection; 00073 //ETX 00074 00077 int CreateSocket(); 00078 00080 void CloseSocket(int socketdescriptor); 00081 00084 int BindSocket(int socketdescriptor, int port); 00085 00088 int SelectSocket(int socketdescriptor, unsigned long msec); 00089 00092 int Accept(int socketdescriptor); 00093 00096 int Listen(int socketdescriptor); 00097 00099 int Connect(int socketdescriptor, const char* hostname, int port); 00100 00102 int GetPort(int socketdescriptor); 00103 00104 private: 00105 vtkSocket(const vtkSocket&); // Not implemented. 00106 void operator=(const vtkSocket&); // Not implemented. 00107 }; 00108 00109 00110 #endif 00111