X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=include%2Fsocketengine.h;h=4c897a7c079df3eb121c113b982d9059110df1dc;hb=dce58b1611e275118d418bfb3b4402bd14d279dd;hp=9c45bcf21fd42a48321a0032ae712a28bf48ab24;hpb=939cb0ba987f927f1ad900d45f98ba6d8e03e9d4;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/include/socketengine.h b/include/socketengine.h index 9c45bcf21..4c897a7c0 100644 --- a/include/socketengine.h +++ b/include/socketengine.h @@ -2,7 +2,7 @@ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * - * InspIRCd: (C) 2002-2009 InspIRCd Development Team + * InspIRCd: (C) 2002-2010 InspIRCd Development Team * See: http://wiki.inspircd.org/Credits * * This program is free but copyrighted software; see @@ -18,6 +18,7 @@ #include #include #include "inspircd_config.h" +#include "socket.h" #include "base.h" /** Types of event an EventHandler may receive. @@ -62,7 +63,7 @@ enum EventMask * it may not require a system call to transition from FD_WANT_FAST_READ */ FD_WANT_EDGE_READ = 0x8, - + /** Mask for all read events */ FD_WANT_READ_MASK = 0x0F, @@ -71,8 +72,10 @@ enum EventMask FD_WANT_NO_WRITE = 0x10, /** Give a write event at all times when writes will not block. * - * You probably don't need to use this state; try your write first, and - * then use FD_WANT_FAST_WRITE. + * You probably shouldn't use this state; if it's likely that the write + * will not block, try it first, then use FD_WANT_FAST_WRITE if it + * fails. If it's likely to block (or you are using polling-style reads) + * then use FD_WANT_SINGLE_WRITE. */ FD_WANT_POLL_WRITE = 0x20, /** Give a write event when writes don't block any more @@ -95,19 +98,23 @@ enum EventMask * FD_WANT_FAST_WRITE when writing data to a mostly-unblocked socket. */ FD_WANT_EDGE_WRITE = 0x80, + /** Request a one-shot poll-style write notification. The socket will + * return to the FD_WANT_NO_WRITE state before HandleEvent is called. + */ + FD_WANT_SINGLE_WRITE = 0x100, /** Mask for all write events */ - FD_WANT_WRITE_MASK = 0xF0, + FD_WANT_WRITE_MASK = 0x1F0, /** Add a trial read. During the next DispatchEvents invocation, this * will call HandleEvent with EVENT_READ unless reads are known to be - * blocking. Useful for edge-triggered reads; does nothing if - * FD_READ_WILL_BLOCK has been set on this EventHandler. + * blocking. */ - FD_ADD_TRIAL_READ = 0x100, + FD_ADD_TRIAL_READ = 0x1000, /** Assert that reads are known to block. This cancels FD_ADD_TRIAL_READ. + * Reset by SE before running EVENT_READ */ - FD_READ_WILL_BLOCK = 0x200, + FD_READ_WILL_BLOCK = 0x2000, /** Add a trial write. During the next DispatchEvents invocation, this * will call HandleEvent with EVENT_WRITE unless writes are known to be @@ -117,20 +124,16 @@ enum EventMask * send() syscall, or to ensure that writes are blocking when attempting * to use FD_WANT_FAST_WRITE. */ - FD_ADD_TRIAL_WRITE = 0x1000, + FD_ADD_TRIAL_WRITE = 0x4000, /** Assert that writes are known to block. This cancels FD_ADD_TRIAL_WRITE. + * Reset by SE before running EVENT_WRITE */ - FD_WRITE_WILL_BLOCK = 0x2000, + FD_WRITE_WILL_BLOCK = 0x8000, - /** Mask for trial read/write items */ - FD_TRIAL_NOTE_MASK = 0x1100, - /** Mask for read/write blocking notifications */ - FD_BLOCK_NOTE_MASK = 0x2200 + /** Mask for trial read/trial write */ + FD_TRIAL_NOTE_MASK = 0x5000 }; -class InspIRCd; -class Module; - /** This class is a basic I/O handler class. * Any object which wishes to receive basic I/O events * from the socketengine must derive from this class and @@ -149,7 +152,7 @@ class Module; * must have a file descriptor. What this file descriptor * is actually attached to is completely up to you. */ -class CoreExport EventHandler : public Extensible +class CoreExport EventHandler : public classbase { private: /** Private state maintained by socket engine */ @@ -357,100 +360,97 @@ public: * @param fd This version of the call takes an EventHandler instead of a bare file descriptor. * @return This method should return exactly the same values as the system call it emulates. */ - virtual int Accept(EventHandler* fd, sockaddr *addr, socklen_t *addrlen); + int Accept(EventHandler* fd, sockaddr *addr, socklen_t *addrlen); /** Abstraction for BSD sockets close(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. * @return This method should return exactly the same values as the system call it emulates. */ - virtual int Close(EventHandler* fd); + int Close(EventHandler* fd); /** Abstraction for BSD sockets close(2). * This function should emulate its namesake system call exactly. * This function should emulate its namesake system call exactly. * @return This method should return exactly the same values as the system call it emulates. */ - virtual int Close(int fd); + int Close(int fd); /** Abstraction for BSD sockets send(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. * @return This method should return exactly the same values as the system call it emulates. */ - virtual int Send(EventHandler* fd, const void *buf, size_t len, int flags); + int Send(EventHandler* fd, const void *buf, size_t len, int flags); /** 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. * @return This method should return exactly the same values as the system call it emulates. */ - virtual int Recv(EventHandler* fd, void *buf, size_t len, int flags); + int Recv(EventHandler* fd, void *buf, size_t len, int flags); /** Abstraction for BSD sockets recvfrom(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. * @return This method should return exactly the same values as the system call it emulates. */ - virtual int RecvFrom(EventHandler* fd, void *buf, size_t len, int flags, sockaddr *from, socklen_t *fromlen); + int RecvFrom(EventHandler* fd, void *buf, size_t len, int flags, sockaddr *from, socklen_t *fromlen); /** Abstraction for BSD sockets sendto(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. * @return This method should return exactly the same values as the system call it emulates. */ - virtual int SendTo(EventHandler* fd, const void *buf, size_t len, int flags, const sockaddr *to, socklen_t tolen); + int SendTo(EventHandler* fd, const void *buf, size_t len, int flags, const sockaddr *to, socklen_t tolen); /** Abstraction for BSD sockets connect(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. * @return This method should return exactly the same values as the system call it emulates. */ - virtual int Connect(EventHandler* fd, const sockaddr *serv_addr, socklen_t addrlen); + int Connect(EventHandler* fd, const sockaddr *serv_addr, socklen_t addrlen); /** Make a file descriptor blocking. * @param fd a file descriptor to set to blocking mode * @return 0 on success, -1 on failure, errno is set appropriately. */ - virtual int Blocking(int fd); + int Blocking(int fd); /** Make a file descriptor nonblocking. * @param fd A file descriptor to set to nonblocking mode * @return 0 on success, -1 on failure, errno is set appropriately. */ - virtual int NonBlocking(int fd); + int NonBlocking(int fd); /** Abstraction for BSD sockets shutdown(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. * @return This method should return exactly the same values as the system call it emulates. */ - virtual int Shutdown(EventHandler* fd, int how); + int Shutdown(EventHandler* fd, int how); /** Abstraction for BSD sockets shutdown(2). * This function should emulate its namesake system call exactly. * @return This method should return exactly the same values as the system call it emulates. */ - virtual int Shutdown(int fd, int how); + int Shutdown(int fd, int how); /** Abstraction for BSD sockets bind(2). * This function should emulate its namesake system call exactly. * @return This method should return exactly the same values as the system call it emulates. */ - virtual int Bind(int fd, const sockaddr *my_addr, socklen_t addrlen); + int Bind(int fd, const irc::sockets::sockaddrs& addr); /** Abstraction for BSD sockets listen(2). * This function should emulate its namesake system call exactly. * @return This method should return exactly the same values as the system call it emulates. */ - virtual int Listen(int sockfd, int backlog); + int Listen(int sockfd, int backlog); - /** Abstraction for BSD sockets getsockname(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. - * @return This method should return exactly the same values as the system call it emulates. + /** Set SO_REUSEADDR and SO_LINGER on this file descriptor */ - virtual int GetSockName(EventHandler* fd, sockaddr *name, socklen_t* namelen); + void SetReuse(int sockfd); /** This function is called immediately after fork(). * Some socket engines (notably kqueue) cannot have their @@ -468,5 +468,7 @@ public: void GetStats(float &kbitpersec_in, float &kbitpersec_out, float &kbitpersec_total); }; +SocketEngine* CreateSocketEngine(); + #endif