Removing epoll in favor of more cross-platform poll - also adding RTMP push support and Buffer push support with IP security

This commit is contained in:
Thulinma 2011-09-22 06:56:39 +02:00
parent 0504061797
commit 3aa7e4d114
2 changed files with 28 additions and 0 deletions

View file

@ -3,6 +3,11 @@
/// Written by Jaron Vietor in 2010 for DDVTech
#include "socket.h"
#include <poll.h>
#ifdef __FreeBSD__
#include <netinet/in.h>
#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(){

View file

@ -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.