comparison C++/modules/Socket/SocketTcp.cpp @ 346:d235553e47a9

Socket: - SocketListener is now implemented as a template and use the backend as the template parameter. No more virtual implementation, - Improve backend detection and set the default backend implementation automatically, - Rename Socket::init to Socket::initialize for non-Windows systems, - Rename SocketListener::(select|selectMultiple) to wait|waitMultiple - Coming up soon: kqueue and epoll backends.
author David Demelier <markand@malikania.fr>
date Thu, 02 Apr 2015 17:32:51 +0200
parents 486767e1d165
children 5a1ec6603230
comparison
equal deleted inserted replaced
345:c293dbe181c0 346:d235553e47a9
131 connect(address); 131 connect(address);
132 } catch (const SocketError &ex) { 132 } catch (const SocketError &ex) {
133 if (ex.code() == SocketError::WouldBlockWrite) { 133 if (ex.code() == SocketError::WouldBlockWrite) {
134 SocketListener listener{{*this, SocketListener::Write}}; 134 SocketListener listener{{*this, SocketListener::Write}};
135 135
136 listener.select(timeout); 136 listener.wait(timeout);
137 137
138 // Socket is writable? Check if there is an error 138 // Socket is writable? Check if there is an error
139 139
140 int error = get<int>(SOL_SOCKET, SO_ERROR); 140 int error = get<int>(SOL_SOCKET, SO_ERROR);
141 141
159 159
160 SocketTcp SocketTcp::waitAccept(SocketAddress &info, int timeout) 160 SocketTcp SocketTcp::waitAccept(SocketAddress &info, int timeout)
161 { 161 {
162 SocketListener listener{{*this, SocketListener::Read}}; 162 SocketListener listener{{*this, SocketListener::Read}};
163 163
164 listener.select(timeout); 164 listener.wait(timeout);
165 165
166 return accept(info); 166 return accept(info);
167 } 167 }
168 168
169 unsigned SocketTcp::recv(void *data, unsigned dataLen) 169 unsigned SocketTcp::recv(void *data, unsigned dataLen)
196 196
197 unsigned SocketTcp::waitRecv(void *data, unsigned length, int timeout) 197 unsigned SocketTcp::waitRecv(void *data, unsigned length, int timeout)
198 { 198 {
199 SocketListener listener{{*this, SocketListener::Read}}; 199 SocketListener listener{{*this, SocketListener::Read}};
200 200
201 listener.select(timeout); 201 listener.wait(timeout);
202 202
203 return recv(data, length); 203 return recv(data, length);
204 } 204 }
205 205
206 unsigned SocketTcp::send(const void *data, unsigned length) 206 unsigned SocketTcp::send(const void *data, unsigned length)
231 231
232 unsigned SocketTcp::waitSend(const void *data, unsigned length, int timeout) 232 unsigned SocketTcp::waitSend(const void *data, unsigned length, int timeout)
233 { 233 {
234 SocketListener listener{{*this, SocketListener::Write}}; 234 SocketListener listener{{*this, SocketListener::Write}};
235 235
236 listener.select(timeout); 236 listener.wait(timeout);
237 237
238 return send(data, length); 238 return send(data, length);
239 } 239 }