VR-Link API Documentation for DIS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vlAsyncSocket.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2005 MaK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 /*******************************************************************************
6 ** $RCSfile: vlAsyncSocket.h,v $ $Revision: 1.2.6.1 $ $State: Exp $
7 *******************************************************************************/
8 #ifndef vlAsyncSocket_H_
9 #define vlAsyncSocket_H_
10 
14 
15 #ifndef VXWORKS
16 
17 #include "vlNetSocket.h"
18 #include <vlutil/vlMutex.h>
19 #include <vlutil/vlThreadSafe.h>
21 #include <vlutil/vlRunnable.h>
22 #include <deque>
23 
24 
25 
26 #ifdef DtUSE_UTILITIES_NAMESPACE
27 namespace DtUSE_UTILITIES_NAMESPACE
28 {
29 #endif
30 
37 {
38 public:
40  DtAsyncSocketPacket(int size, const char *data, DtIpv4Addr addr=0);
42  virtual ~DtAsyncSocketPacket();
43 
44 
45  DtAsyncSocketPacket &operator=(const DtAsyncSocketPacket &other);
46 
47  size_t size() const { return mySize;}
48  char * data() { return &myData[0];}
49  DtIpv4Addr addr() const { return myAddr;}
50 
51 protected:
52 
53  int mySize;
54  std::vector<char> myData;
56 
57 };
58 
66 {
67  public:
68 
69  DtAsyncNetSocket(int port = DtDEFAULT_PORT,
70  DtU8 flags = DtReadWrite, DtIpv4Addr devAddr = 0);
71 
72  DtAsyncNetSocket(int port,
73  DtIpv4Addr destAddr, DtU8 flags,
74  DtIpv4Addr devAddr = 0);
75 
76  DtAsyncNetSocket(char* dummy, int sockfd, DtU8 flags = DtReadWrite);
77 
79  virtual ~DtAsyncNetSocket();
80 
81  private:
82 
85 
87  DtAsyncNetSocket & operator=(const DtAsyncNetSocket &);
88 
89  public:
90 
96  virtual int sendTo(caddr_t packet, size_t size, DtIpv4Addr addr);
97 
100  virtual int directSendTo(caddr_t packet, size_t size, DtIpv4Addr addr);
101 
103  virtual bool usingAsyncSend() const;
104  virtual void setUsingAsyncSend(bool b);
105 
107  virtual bool usingAsyncReceive() const;
108  virtual void setUsingAsyncReceive(bool b);
109 
110  protected:
111 
114  virtual int recvFromNet(caddr_t *buffptr);
115 
117  void initThread();
118 
120  virtual void workerSendThread();
121 
123  virtual void workerReceiveThread();
124 
127  virtual void processSendQueue();
128 
130  virtual void processReceiveQueue();
131 
132  protected:
135 #ifdef _WIN32
136  static unsigned long runReceive(void* usr_data);
137  static unsigned long runSend(void *user_data);
138 #else
139  static void* runReceive(void* usr_data);
140  static void* runSend(void* usr_data);
141 #endif
142  static void setQueueTimeout(double new_time_out);
143  static double queueTimeout();
144 
145  protected:
146 
148  static double theQueueTimeout;
149 
150 
151  protected:
152 
154 
157 
160 
163 
164  volatile bool myTimeToQuitSender;
165  volatile bool myTimeToQuitReceiver;
167 
168 #ifdef _WIN32
169  HANDLE mySendThreadHandle;
170  HANDLE myReceiveThreadHandle;
171  HANDLE mySendEvent;
172  HANDLE myReceiveEvent;
173 #else
176  int mySendEvent[2];
177 #endif
178 
179 };
180 
181 inline void
183 {
184  theQueueTimeout = time_out;
185 }
186 
187 inline double
189 {
190  return theQueueTimeout;
191 }
192 inline bool
194 {
195  return myUseAsyncSendFlag;
196 }
197 
198 inline void
200 {
201  myUseAsyncSendFlag = b;
202 }
203 inline bool
205 {
206  return myUseAsyncReceiveFlag;
207 }
208 
209 inline void
211 {
212  myUseAsyncReceiveFlag = b;
213 }
214 
215 #ifdef DtUSE_UTILITIES_NAMESPACE
216 }
217 #endif
218 
219 #endif
220 #endif
221 
bool myUseAsyncSendFlag
Definition: vlAsyncSocket.h:155
DtU32 DtIpv4Addr
Definition: vlUtil.h:330
This file contains the declaration of DtMutex.
A Socket which starts a thread which is continuously reading and writing from packet queues...
Definition: vlAsyncSocket.h:65
DtIpv4Addr addr() const
Definition: vlAsyncSocket.h:49
static void setQueueTimeout(double new_time_out)
Definition: vlAsyncSocket.h:182
bool myUseAsyncReceiveFlag
Definition: vlAsyncSocket.h:156
ThreadSafePacketQueue myReceiveQueue
A type safe queue for getting messages from the network reader.
Definition: vlAsyncSocket.h:162
#define DtDEFAULT_PORT
Definition: vlSocket.h:49
int mySize
Definition: vlAsyncSocket.h:53
virtual bool usingAsyncReceive() const
Get/Set function for configuring AsyncInput. (True by default)
Definition: vlAsyncSocket.h:204
size_t size() const
Definition: vlAsyncSocket.h:47
pthread_t myReceiveThreadHandle
Definition: vlAsyncSocket.h:175
Contains declaration of DtRunnable abstract class.
virtual void setUsingAsyncSend(bool b)
Definition: vlAsyncSocket.h:199
unsigned char DtU8
An eight bit unsigned integer value.
Definition: vlMachineTypes.h:137
static double queueTimeout()
Definition: vlAsyncSocket.h:188
Encapsulates a packet which is to be either received or transmitted over the network by the DtAsyncSo...
Definition: vlAsyncSocket.h:36
volatile bool myTimeToQuitReceiver
Definition: vlAsyncSocket.h:165
DtIpv4Addr myAddr
Definition: vlAsyncSocket.h:55
pthread_t mySendThreadHandle
Definition: vlAsyncSocket.h:174
DtThreadSafe< std::deque< DtAsyncSocketPacket > > ThreadSafePacketQueue
Definition: vlAsyncSocket.h:153
#define DtReadWrite
Marks the Socket as Read and Writable.
Definition: vlInetSocket.h:37
volatile bool myTimeToQuitSender
Definition: vlAsyncSocket.h:164
std::vector< char > myData
Definition: vlAsyncSocket.h:54
#define DT_DLL_NETCOMPAT
Definition: vlMachineTypes.h:111
static double theQueueTimeout
The TimeOut in the send Thread, in seconds.
Definition: vlAsyncSocket.h:148
This file declares DtNetSocket, as well as several enumerations and constants needed for its use...
ThreadSafePacketQueue mySendQueue
A type save queue for sending messages to the network writer.
Definition: vlAsyncSocket.h:159
a thread safe interface to a value.
Definition: vlThreadSafe.h:104
Defines a ThreadedObject which can run a DtRunnable object in a thread.
Defines a thread-safe template class for variables.
char * data()
Definition: vlAsyncSocket.h:48
virtual bool usingAsyncSend() const
Get/Set functions to configure AsyncOutput (True by default)
Definition: vlAsyncSocket.h:193
A DtSocket that implements network sending and receiving function using IP/UDP broadcast, multicast or unicast.
Definition: vlNetSocket.h:72
virtual void setUsingAsyncReceive(bool b)
Definition: vlAsyncSocket.h:210
char * myThreadPktBuff
Definition: vlAsyncSocket.h:166

Document ID: Generated on Thu Sep 19 02:12:35 EDT 2024 from SVN revision 269601
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)