VR-Link API Documentation for HLA 1516
 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 

Document ID: Generated on Tue Mar 1 02:56:17 EST 2016 from SVN revision 162687
Copyright © 2005-2014 VT MÄK. All Rights Reserved (www.mak.com)