Changeset 110:9ac6386fe9ff in xplra for src/client/c/hu/varadiistvan
- Timestamp:
- 12/23/22 09:09:50 (2 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- src/client/c/hu/varadiistvan/xplra
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/client/c/hu/varadiistvan/xplra/XPlane.cc
r107 r110 35 35 36 36 #include <hu/varadiistvan/scpl/io/LocalClientSocket.h> 37 #include <hu/varadiistvan/scpl/io/TCPClientSocket.h> 37 38 #include <hu/varadiistvan/scpl/io/DataStream.h> 38 39 … … 52 53 53 54 using hu::varadiistvan::scpl::io::LocalClientSocket; 54 using hu::varadiistvan::scpl::io:: LocalConnector;55 using hu::varadiistvan::scpl::io::TCPClientSocket; 55 56 using hu::varadiistvan::scpl::io::DataStream; 56 57 … … 60 61 using std::string; 61 62 using std::min; 63 64 //------------------------------------------------------------------------------ 65 66 const unsigned short XPlane::defaultTCPPort; 67 68 //------------------------------------------------------------------------------ 69 70 template <class ClientSocket> 71 void XPlane::connect(std::unique_ptr<ClientSocket> clientSocket) 72 { 73 auto& connector = clientSocket->getConnector(); 74 75 while (!connector.connect()) { 76 if (connector.failed()) { 77 throw IOException(connector.getErrorCode()); 78 } 79 waiter.wait(); 80 if (waiter.failed()) { 81 throw IOException(waiter.getErrorCode()); 82 } 83 } 84 85 #ifndef _WIN32 86 signal(SIGPIPE, SIG_IGN); 87 #endif 88 89 socket = clientSocket.release(); 90 stream = new DataStream(*socket); 91 92 for(multiBuffers_t::iterator i = multiBuffers.begin(); 93 i!=multiBuffers.end(); ++i) 94 { 95 MultiBuffer* buffer = *i; 96 buffer->reregisterInXPlane(); 97 } 98 } 62 99 63 100 //------------------------------------------------------------------------------ … … 150 187 unique_ptr<LocalClientSocket> clientSocket(new LocalClientSocket("xplra", 151 188 &waiter)); 152 LocalConnector& connector = clientSocket->getConnector(); 153 154 while (!connector.connect()) { 155 if (connector.failed()) { 156 throw IOException(connector.getErrorCode()); 157 } 158 waiter.wait(); 159 if (waiter.failed()) { 160 throw IOException(waiter.getErrorCode()); 161 } 162 } 163 164 #ifndef _WIN32 165 signal(SIGPIPE, SIG_IGN); 166 #endif 167 168 socket = clientSocket.release(); 169 stream = new DataStream(*socket); 170 171 for(multiBuffers_t::iterator i = multiBuffers.begin(); 172 i!=multiBuffers.end(); ++i) 173 { 174 MultiBuffer* buffer = *i; 175 buffer->reregisterInXPlane(); 176 } 189 connect(std::move(clientSocket)); 190 } 191 192 //------------------------------------------------------------------------------ 193 194 void XPlane::connectTCP(const std::string& address, unsigned short port) 195 { 196 if (socket!=0) return; 197 198 unique_ptr<TCPClientSocket> clientSocket(new TCPClientSocket(address.c_str(), 199 port, 200 &waiter)); 201 connect(std::move(clientSocket)); 177 202 } 178 203 -
src/client/c/hu/varadiistvan/xplra/XPlane.h
r107 r110 36 36 37 37 #include <set> 38 #include <memory> 38 39 39 40 #include <inttypes.h> … … 43 44 namespace hu { namespace varadiistvan { namespace scpl { namespace io { 44 45 45 class LocalClientSocket;46 class BufferedStream; 46 47 class DataStream; 47 48 … … 69 70 private: 70 71 /** 72 * The default TCP port. 73 */ 74 static const unsigned short defaultTCPPort = 0x5852; 75 76 /** 71 77 * Type for the set of multi-dataref buffers. 72 78 */ … … 79 85 80 86 /** 81 * The local client socketover which we are communicating with X-Plane.82 */ 83 scpl::io:: LocalClientSocket* socket;87 * The client socket as a stream, over which we are communicating with X-Plane. 88 */ 89 scpl::io::BufferedStream* socket; 84 90 85 91 /** … … 108 114 109 115 /** 110 * Connect to the simulator .116 * Connect to the simulator locally. 111 117 */ 112 118 void connect(); 119 120 /** 121 * Connect to the simulator on TCP to the given address. 122 */ 123 void connectTCP(const std::string& address, 124 unsigned short port = defaultTCPPort); 113 125 114 126 /** … … 363 375 void setArray(const char* name, uint8_t type, size_t length, 364 376 size_t offset); 377 378 /** 379 * Connect with the given socket. 380 */ 381 template <class ClientSocket> 382 void connect(std::unique_ptr<ClientSocket> clientSocket); 365 383 366 384 friend class MultiBuffer;
Note:
See TracChangeset
for help on using the changeset viewer.