/usr/include/Poco/Net/Socket.h is in libpoco-dev 1.3.6p1-5+deb8u1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 | //
// Socket.h
//
// $Id: //poco/1.3/Net/include/Poco/Net/Socket.h#4 $
//
// Library: Net
// Package: Sockets
// Module: Socket
//
// Definition of the Socket class.
//
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef Net_Socket_INCLUDED
#define Net_Socket_INCLUDED
#include "Poco/Net/Net.h"
#include "Poco/Net/SocketImpl.h"
#include <vector>
namespace Poco {
namespace Net {
class Net_API Socket
/// Socket is the common base class for
/// StreamSocket, ServerSocket, DatagramSocket and other
/// socket classes.
///
/// It provides operations common to all socket types.
{
public:
enum SelectMode
/// The mode argument to poll() and select().
{
SELECT_READ = 1,
SELECT_WRITE = 2,
SELECT_ERROR = 4
};
typedef std::vector<Socket> SocketList;
Socket();
/// Creates an uninitialized socket.
Socket(const Socket& socket);
/// Copy constructor.
///
/// Attaches the SocketImpl from the other socket and
/// increments the reference count of the SocketImpl.
Socket& operator = (const Socket& socket);
/// Assignment operator.
///
/// Releases the socket's SocketImpl and
/// attaches the SocketImpl from the other socket and
/// increments the reference count of the SocketImpl.
virtual ~Socket();
/// Destroys the Socket and releases the
/// SocketImpl.
bool operator == (const Socket& socket) const;
/// Returns true if both sockets share the same
/// SocketImpl, false otherwise.
bool operator != (const Socket& socket) const;
/// Returns false if both sockets share the same
/// SocketImpl, true otherwise.
bool operator < (const Socket& socket) const;
/// Compares the SocketImpl pointers.
bool operator <= (const Socket& socket) const;
/// Compares the SocketImpl pointers.
bool operator > (const Socket& socket) const;
/// Compares the SocketImpl pointers.
bool operator >= (const Socket& socket) const;
/// Compares the SocketImpl pointers.
void close();
/// Closes the socket.
static int select(SocketList& readList, SocketList& writeList, SocketList& exceptList, const Poco::Timespan& timeout);
/// Determines the status of one or more sockets,
/// using a call to select().
///
/// ReadList contains the list of sockets which should be
/// checked for readability.
///
/// WriteList contains the list of sockets which should be
/// checked for writeability.
///
/// ExceptList contains a list of sockets which should be
/// checked for a pending error.
///
/// Returns the number of sockets ready.
///
/// After return,
/// * readList contains those sockets ready for reading,
/// * writeList contains those sockets ready for writing,
/// * exceptList contains those sockets with a pending error.
///
/// If the total number of sockets passed in readList, writeList and
/// exceptList is zero, select() will return immediately and the
/// return value will be 0.
///
/// If one of the sockets passed to select() is closed while
/// select() runs, select will return immediately. However,
/// the closed socket will not be included in any list.
/// In this case, the return value may be greater than the sum
/// of all sockets in all list.
bool poll(const Poco::Timespan& timeout, int mode) const;
/// Determines the status of the socket, using a
/// call to select().
///
/// The mode argument is constructed by combining the values
/// of the SelectMode enumeration.
///
/// Returns true if the next operation corresponding to
/// mode will not block, false otherwise.
int available() const;
/// Returns the number of bytes available that can be read
/// without causing the socket to block.
void setSendBufferSize(int size);
/// Sets the size of the send buffer.
int getSendBufferSize() const;
/// Returns the size of the send buffer.
///
/// The returned value may be different than the
/// value previously set with setSendBufferSize(),
/// as the system is free to adjust the value.
void setReceiveBufferSize(int size);
/// Sets the size of the receive buffer.
int getReceiveBufferSize() const;
/// Returns the size of the receive buffer.
///
/// The returned value may be different than the
/// value previously set with setReceiveBufferSize(),
/// as the system is free to adjust the value.
void setSendTimeout(const Poco::Timespan& timeout);
/// Sets the send timeout for the socket.
Poco::Timespan getSendTimeout() const;
/// Returns the send timeout for the socket.
///
/// The returned timeout may be different than the
/// timeout previously set with setSendTimeout(),
/// as the system is free to adjust the value.
void setReceiveTimeout(const Poco::Timespan& timeout);
/// Sets the send timeout for the socket.
///
/// On systems that do not support SO_RCVTIMEO, a
/// workaround using poll() is provided.
Poco::Timespan getReceiveTimeout() const;
/// Returns the receive timeout for the socket.
///
/// The returned timeout may be different than the
/// timeout previously set with getReceiveTimeout(),
/// as the system is free to adjust the value.
void setOption(int level, int option, int value);
/// Sets the socket option specified by level and option
/// to the given integer value.
void setOption(int level, int option, unsigned value);
/// Sets the socket option specified by level and option
/// to the given integer value.
void setOption(int level, int option, unsigned char value);
/// Sets the socket option specified by level and option
/// to the given integer value.
void setOption(int level, int option, const Poco::Timespan& value);
/// Sets the socket option specified by level and option
/// to the given time value.
void setOption(int level, int option, const IPAddress& value);
/// Sets the socket option specified by level and option
/// to the given time value.
void getOption(int level, int option, int& value) const;
/// Returns the value of the socket option
/// specified by level and option.
void getOption(int level, int option, unsigned& value) const;
/// Returns the value of the socket option
/// specified by level and option.
void getOption(int level, int option, unsigned char& value) const;
/// Returns the value of the socket option
/// specified by level and option.
void getOption(int level, int option, Poco::Timespan& value) const;
/// Returns the value of the socket option
/// specified by level and option.
void getOption(int level, int option, IPAddress& value) const;
/// Returns the value of the socket option
/// specified by level and option.
void setLinger(bool on, int seconds);
/// Sets the value of the SO_LINGER socket option.
void getLinger(bool& on, int& seconds) const;
/// Returns the value of the SO_LINGER socket option.
void setNoDelay(bool flag);
/// Sets the value of the TCP_NODELAY socket option.
bool getNoDelay() const;
/// Returns the value of the TCP_NODELAY socket option.
void setKeepAlive(bool flag);
/// Sets the value of the SO_KEEPALIVE socket option.
bool getKeepAlive() const;
/// Returns the value of the SO_KEEPALIVE socket option.
void setReuseAddress(bool flag);
/// Sets the value of the SO_REUSEADDR socket option.
bool getReuseAddress() const;
/// Returns the value of the SO_REUSEADDR socket option.
void setReusePort(bool flag);
/// Sets the value of the SO_REUSEPORT socket option.
/// Does nothing if the socket implementation does not
/// support SO_REUSEPORT.
bool getReusePort() const;
/// Returns the value of the SO_REUSEPORT socket option.
///
/// Returns false if the socket implementation does not
/// support SO_REUSEPORT.
void setOOBInline(bool flag);
/// Sets the value of the SO_OOBINLINE socket option.
bool getOOBInline() const;
/// Returns the value of the SO_OOBINLINE socket option.
void setBlocking(bool flag);
/// Sets the socket in blocking mode if flag is true,
/// disables blocking mode if flag is false.
bool getBlocking() const;
/// Returns the blocking mode of the socket.
/// This method will only work if the blocking modes of
/// the socket are changed via the setBlocking method!
SocketAddress address() const;
/// Returns the IP address and port number of the socket.
SocketAddress peerAddress() const;
/// Returns the IP address and port number of the peer socket.
SocketImpl* impl() const;
/// Returns the SocketImpl for this socket.
static bool supportsIPv4();
/// Returns true if the system supports IPv4.
static bool supportsIPv6();
/// Returns true if the system supports IPv6.
protected:
Socket(SocketImpl* pImpl);
/// Creates the Socket and attaches the given SocketImpl.
/// The socket takes owership of the SocketImpl.
poco_socket_t sockfd() const;
/// Returns the socket descriptor for this socket.
private:
SocketImpl* _pImpl;
};
//
// inlines
//
inline bool Socket::operator == (const Socket& socket) const
{
return _pImpl == socket._pImpl;
}
inline bool Socket::operator != (const Socket& socket) const
{
return _pImpl != socket._pImpl;
}
inline bool Socket::operator < (const Socket& socket) const
{
return _pImpl < socket._pImpl;
}
inline bool Socket::operator <= (const Socket& socket) const
{
return _pImpl <= socket._pImpl;
}
inline bool Socket::operator > (const Socket& socket) const
{
return _pImpl > socket._pImpl;
}
inline bool Socket::operator >= (const Socket& socket) const
{
return _pImpl >= socket._pImpl;
}
inline void Socket::close()
{
_pImpl->close();
}
inline bool Socket::poll(const Poco::Timespan& timeout, int mode) const
{
return _pImpl->poll(timeout, mode);
}
inline int Socket::available() const
{
return _pImpl->available();
}
inline void Socket::setSendBufferSize(int size)
{
_pImpl->setSendBufferSize(size);
}
inline int Socket::getSendBufferSize() const
{
return _pImpl->getSendBufferSize();
}
inline void Socket::setReceiveBufferSize(int size)
{
_pImpl->setReceiveBufferSize(size);
}
inline int Socket::getReceiveBufferSize() const
{
return _pImpl->getReceiveBufferSize();
}
inline void Socket::setSendTimeout(const Poco::Timespan& timeout)
{
_pImpl->setSendTimeout(timeout);
}
inline Poco::Timespan Socket::getSendTimeout() const
{
return _pImpl->getSendTimeout();
}
inline void Socket::setReceiveTimeout(const Poco::Timespan& timeout)
{
_pImpl->setReceiveTimeout(timeout);
}
inline Poco::Timespan Socket::getReceiveTimeout() const
{
return _pImpl->getReceiveTimeout();
}
inline void Socket::setOption(int level, int option, int value)
{
_pImpl->setOption(level, option, value);
}
inline void Socket::setOption(int level, int option, unsigned value)
{
_pImpl->setOption(level, option, value);
}
inline void Socket::setOption(int level, int option, unsigned char value)
{
_pImpl->setOption(level, option, value);
}
inline void Socket::setOption(int level, int option, const Poco::Timespan& value)
{
_pImpl->setOption(level, option, value);
}
inline void Socket::setOption(int level, int option, const IPAddress& value)
{
_pImpl->setOption(level, option, value);
}
inline void Socket::getOption(int level, int option, int& value) const
{
_pImpl->getOption(level, option, value);
}
inline void Socket::getOption(int level, int option, unsigned& value) const
{
_pImpl->getOption(level, option, value);
}
inline void Socket::getOption(int level, int option, unsigned char& value) const
{
_pImpl->getOption(level, option, value);
}
inline void Socket::getOption(int level, int option, Poco::Timespan& value) const
{
_pImpl->getOption(level, option, value);
}
inline void Socket::getOption(int level, int option, IPAddress& value) const
{
_pImpl->getOption(level, option, value);
}
inline void Socket::setLinger(bool on, int seconds)
{
_pImpl->setLinger(on, seconds);
}
inline void Socket::getLinger(bool& on, int& seconds) const
{
_pImpl->getLinger(on, seconds);
}
inline void Socket::setNoDelay(bool flag)
{
_pImpl->setNoDelay(flag);
}
inline bool Socket::getNoDelay() const
{
return _pImpl->getNoDelay();
}
inline void Socket::setKeepAlive(bool flag)
{
_pImpl->setKeepAlive(flag);
}
inline bool Socket::getKeepAlive() const
{
return _pImpl->getKeepAlive();
}
inline void Socket::setReuseAddress(bool flag)
{
_pImpl->setReuseAddress(flag);
}
inline bool Socket::getReuseAddress() const
{
return _pImpl->getReuseAddress();
}
inline void Socket::setReusePort(bool flag)
{
_pImpl->setReusePort(flag);
}
inline bool Socket::getReusePort() const
{
return _pImpl->getReusePort();
}
inline void Socket::setOOBInline(bool flag)
{
_pImpl->setOOBInline(flag);
}
inline bool Socket::getOOBInline() const
{
return _pImpl->getOOBInline();
}
inline void Socket::setBlocking(bool flag)
{
_pImpl->setBlocking(flag);
}
inline bool Socket::getBlocking() const
{
return _pImpl->getBlocking();
}
inline SocketImpl* Socket::impl() const
{
return _pImpl;
}
inline poco_socket_t Socket::sockfd() const
{
return _pImpl->sockfd();
}
inline SocketAddress Socket::address() const
{
return _pImpl->address();
}
inline SocketAddress Socket::peerAddress() const
{
return _pImpl->peerAddress();
}
inline bool Socket::supportsIPv4()
{
return true;
}
inline bool Socket::supportsIPv6()
{
#if defined(POCO_HAVE_IPv6)
return true;
#else
return false;
#endif
}
} } // namespace Poco::Net
#endif // Net_Socket_INCLUDED
|