+ if (option == SO_NONBLOCK)
+ {
+#ifdef HAVE_FCNTL
+ int flags = fcntl(mImpl.fd, F_GETFL);
+ return flags & O_NONBLOCK;
+#else
+ return ioctl(mImpl.fd, FIONBIO, &value);
+#endif
+ }
+ socklen_t optlen = sizeof(value);
+ return getsockopt(mImpl.fd, SOL_SOCKET, option, &value, &optlen);
+ }
+
+ /**
+ * Get a string socket option.
+ * \param option The option to set.
+ * \param value The new value.
+ * \return 0 on success, -1 on failure.
+ */
+ int get(int option, std::string& value)
+ {
+ char str[256] = {'\0'};
+ socklen_t optlen = sizeof(str);
+ int result = getsockopt(mImpl.fd, SOL_SOCKET, option,
+ &str, &optlen);
+ value = str;
+ return result;
+ }
+
+
+ /**
+ * Write some bytes to the socket. Use this for connected sockets.
+ * \param bytes The bytes.
+ * \param size The number of bytes.
+ * \param flags The send options.
+ * \return The number of bytes written.
+ */
+ ssize_t write(const void* bytes, size_t size, int flags = 0)
+ {
+ return send(mImpl.fd, bytes, size, flags);
+ }
+
+ /**
+ * Write some bytes to the socket using the given address. Use this
+ * for unconnected sockets.
+ * \param bytes The bytes.
+ * \param size The number of bytes.
+ * \param address The address to send to.
+ * \param flags The send options.
+ * \return The number of bytes written.
+ */
+ ssize_t write(const void* bytes, size_t size,
+ const SocketAddress& address, int flags = 0)
+ {
+ return sendto(mImpl.fd, bytes, size, flags,
+ address.address(), address.size());
+ }
+
+ /**
+ * Write a packet to the socket. Use this for connected sockets.
+ * \param packet The packet.
+ * \param flags The send options.
+ * \return The number of bytes written.
+ */
+ ssize_t write(const Packet& packet, int flags = 0)
+ {
+ return write(packet.bytes(), packet.size(), flags);
+ }
+
+ /**
+ * Write a packet to the socket using the given address. Use this for
+ * unconnected sockets.
+ * \param packet The packet.
+ * \param address The address to send to.
+ * \param flags The send options.
+ * \return The number of bytes written.
+ */
+ ssize_t write(const Packet& packet, const SocketAddress& address,
+ int flags = 0)
+ {
+ return write(packet.bytes(), packet.size(), address, flags);
+ }
+