From 3aa7e4d114af9f28190f2e964080a01ee4da5b68 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Thu, 22 Sep 2011 06:56:39 +0200 Subject: [PATCH] Removing epoll in favor of more cross-platform poll - also adding RTMP push support and Buffer push support with IP security --- util/socket.cpp | 26 ++++++++++++++++++++++++++ util/socket.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/util/socket.cpp b/util/socket.cpp index ecb1dab5..b0046d02 100644 --- a/util/socket.cpp +++ b/util/socket.cpp @@ -3,6 +3,11 @@ /// Written by Jaron Vietor in 2010 for DDVTech #include "socket.h" +#include + +#ifdef __FreeBSD__ +#include +#endif /// Create a new base socket. This is a basic constructor for converting any valid socket to a Socket::Connection. /// \param sockNo Integer representing the socket to convert. @@ -69,6 +74,27 @@ Socket::Connection::Connection(std::string address, bool nonblock){ } }//Socket::Connection Unix Contructor +/// Calls poll() on the socket, checking if data is available. +/// This function may return true even if there is no data, but never returns false when there is. +bool Socket::Connection::canRead(){ + struct pollfd PFD; + PFD.fd = sock; + PFD.events = POLLIN; + PFD.revents = 0; + poll(&PFD, 1, 5); + return (PFD.revents & POLLIN) == POLLIN; +} +/// Calls poll() on the socket, checking if data can be written. +bool Socket::Connection::canWrite(){ + struct pollfd PFD; + PFD.fd = sock; + PFD.events = POLLOUT; + PFD.revents = 0; + poll(&PFD, 1, 5); + return (PFD.revents & POLLOUT) == POLLOUT; +} + + /// Returns the ready-state for this socket. /// \returns 1 if data is waiting to be read, -1 if not connected, 0 otherwise. signed int Socket::Connection::ready(){ diff --git a/util/socket.h b/util/socket.h index 9aa754be..57aca183 100644 --- a/util/socket.h +++ b/util/socket.h @@ -27,6 +27,8 @@ namespace Socket{ Connection(); ///< Create a new disconnected base socket. Connection(int sockNo); ///< Create a new base socket. Connection(std::string adres, bool nonblock = false); ///< Create a new Unix Socket. + bool canRead(); ///< Calls poll() on the socket, checking if data is available. + bool canWrite(); ///< Calls poll() on the socket, checking if data can be written. bool Error; ///< Set to true if a socket error happened. bool Blocking; ///< Set to true if a socket is currently or wants to be blocking. signed int ready(); ///< Returns the ready-state for this socket.