X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=include%2Fsocketengine.h;h=ddc48f94d159a359ae8d8f27bfc5534a515aa314;hb=7770cd985405c7630e9149fc08c314ec824a9c75;hp=3a15e98c1475cfefd252596c85913754ef4d0812;hpb=f71e6bf9cb41811f18864f5d4eecb26e29d03f25;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/include/socketengine.h b/include/socketengine.h index 3a15e98c1..ddc48f94d 100644 --- a/include/socketengine.h +++ b/include/socketengine.h @@ -29,22 +29,13 @@ #include "socket.h" #include "base.h" -/** Types of event an EventHandler may receive. - * EVENT_READ is a readable file descriptor, - * and EVENT_WRITE is a writeable file descriptor. - * EVENT_ERROR can always occur, and indicates - * a write error or read error on the socket, - * e.g. EOF condition or broken pipe. - */ -enum EventType -{ - /** Read event */ - EVENT_READ = 0, - /** Write event */ - EVENT_WRITE = 1, - /** Error event */ - EVENT_ERROR = 2 -}; +#ifndef _WIN32 +#include +#endif + +#ifndef IOV_MAX +#define IOV_MAX 1024 +#endif /** * Event mask for SocketEngine events @@ -199,16 +190,20 @@ class CoreExport EventHandler : public classbase */ virtual ~EventHandler() {} - /** Process an I/O event. - * You MUST implement this function in your derived - * class, and it will be called whenever read or write - * events are received. - * @param et either one of EVENT_READ for read events, - * EVENT_WRITE for write events and EVENT_ERROR for - * error events. - * @param errornum The error code which goes with an EVENT_ERROR. + /** Called by the socket engine in case of a read event */ - virtual void HandleEvent(EventType et, int errornum = 0) = 0; + virtual void OnEventHandlerRead() = 0; + + /** Called by the socket engine in case of a write event. + * The default implementation does nothing. + */ + virtual void OnEventHandlerWrite(); + + /** Called by the socket engine in case of an error event. + * The default implementation does nothing. + * @param errornum Error code + */ + virtual void OnEventHandlerError(int errornum); friend class SocketEngine; }; @@ -306,6 +301,12 @@ class CoreExport SocketEngine } public: +#ifndef _WIN32 + typedef iovec IOVector; +#else + typedef WindowsIOVec IOVector; +#endif + /** Constructor. * The constructor transparently initializes * the socket engine which the ircd is using. @@ -346,8 +347,10 @@ public: */ static void ChangeEventMask(EventHandler* eh, int event_mask); - /** Returns the highest file descriptor you may store in the socket engine - * @return The maximum fd value + /** Returns the number of file descriptors reported by the system this program may use + * when it was started. + * @return If positive, the number of file descriptors that the system reported that we + * may use. Otherwise (<= 0) this number could not be determined. */ static int GetMaxFds() { return MAX_DESCRIPTORS; } @@ -432,6 +435,27 @@ public: */ static int Send(EventHandler* fd, const void *buf, size_t len, int flags); + /** Abstraction for vector write function writev(). + * This function should emulate its namesake system call exactly. + * @param fd EventHandler to send data with + * @param iov Array of IOVectors containing the buffers to send and their lengths in the platform's + * native format. + * @param count Number of elements in iov. + * @return This method should return exactly the same values as the system call it emulates. + */ + static int WriteV(EventHandler* fd, const IOVector* iov, int count); + +#ifdef _WIN32 + /** Abstraction for vector write function writev() that accepts a POSIX format iovec. + * This function should emulate its namesake system call exactly. + * @param fd EventHandler to send data with + * @param iov Array of iovecs containing the buffers to send and their lengths in POSIX format. + * @param count Number of elements in iov. + * @return This method should return exactly the same values as the system call it emulates. + */ + static int WriteV(EventHandler* fd, const iovec* iov, int count); +#endif + /** Abstraction for BSD sockets recv(2). * This function should emulate its namesake system call exactly. * @param fd This version of the call takes an EventHandler instead of a bare file descriptor.