diff options
| author | Adam <Adam@anope.org> | 2010-09-17 19:20:07 -0400 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2010-09-17 19:20:07 -0400 |
| commit | 227909e2cf0039737dc52872651837fe5f1702b5 (patch) | |
| tree | b8a7072c7d938ea66d9710a48d717b3eb76343de /include | |
| parent | f71fb6e8133da955a58b1cca00013ce20c0b65cc (diff) | |
Rejig of some of the socket stuff. Fixed marking sockets as nonblocking on Windows. Added in a LastError function to keep having to use strerror/GetLastError everywhere.
Diffstat (limited to 'include')
| -rw-r--r-- | include/anope.h | 5 | ||||
| -rw-r--r-- | include/dns.h | 2 | ||||
| -rw-r--r-- | include/modules.h | 2 | ||||
| -rw-r--r-- | include/services.h | 1 | ||||
| -rw-r--r-- | include/sockets.h | 52 |
5 files changed, 26 insertions, 36 deletions
diff --git a/include/anope.h b/include/anope.h index a63abb9d1..cbc87bf7b 100644 --- a/include/anope.h +++ b/include/anope.h @@ -337,6 +337,11 @@ namespace Anope */ extern CoreExport void Unhex(const Anope::string &src, Anope::string &dest); extern CoreExport void Unhex(const Anope::string &src, char *dest); + + /** Return the last error, uses errno/GetLastError() to determin this + * @return An error message + */ + extern CoreExport const Anope::string LastError(); } /** sepstream allows for splitting token seperated lists. diff --git a/include/dns.h b/include/dns.h index 51960b0f4..4f61ef909 100644 --- a/include/dns.h +++ b/include/dns.h @@ -134,7 +134,7 @@ class DNSSocket : public ClientSocket int SendTo(const unsigned char *buf, size_t len) const; int RecvFrom(char *buf, size_t size, sockaddrs &addrs) const; public: - DNSSocket(const Anope::string &nTargetHost, int nPort); + DNSSocket(const Anope::string &nTargetHost, int Port); virtual ~DNSSocket(); bool ProcessRead(); diff --git a/include/modules.h b/include/modules.h index ac76a4534..5748d4c10 100644 --- a/include/modules.h +++ b/include/modules.h @@ -27,6 +27,7 @@ # define dlsym(file, symbol) (HMODULE)GetProcAddress(file, symbol) # define dlclose(file) FreeLibrary(file) ? 0 : 1 # define ano_modclearerr() SetLastError(0) +# define ano_moderr() LastError().c_str() #else typedef void * ano_module_t; @@ -36,6 +37,7 @@ * to be cleared, POSIX-wise. -GD */ # define ano_modclearerr() dlerror() +# define ano_moderr() dlerror() #endif /** Possible return types from events. diff --git a/include/services.h b/include/services.h index 36e2f8e90..9fd9b2ce3 100644 --- a/include/services.h +++ b/include/services.h @@ -80,7 +80,6 @@ # define MARK_DEPRECATED # define EINPROGRESS WSAEWOULDBLOCK -extern CoreExport const char *dlerror(); extern CoreExport int inet_pton(int af, const char *src, void *dst); extern CoreExport const char *inet_ntop(int af, const void *src, char *dst, size_t size); #endif diff --git a/include/sockets.h b/include/sockets.h index 6caeea19c..38060ed78 100644 --- a/include/sockets.h +++ b/include/sockets.h @@ -105,10 +105,10 @@ enum SocketFlag class CoreExport Socket : public Flags<SocketFlag, 2> { protected: - /** Really recieve something from the buffer + /** Really receive something from the buffer * @param buf The buf to read to * @param sz How much to read - * @return Number of bytes recieved + * @return Number of bytes received */ virtual int RecvInternal(char *buf, size_t sz) const; @@ -120,13 +120,11 @@ class CoreExport Socket : public Flags<SocketFlag, 2> /* Socket FD */ int Sock; - /* Port we're connected to */ - int Port; /* Is this an IPv6 socket? */ bool IPv6; /* Things to be written to the socket */ std::string WriteBuffer; - /* Part of a message sent from the server, but not totally recieved */ + /* Part of a message sent from the server, but not totally received */ std::string extrabuf; /* How much data was received from this socket */ size_t RecvLen; @@ -180,7 +178,7 @@ class CoreExport Socket : public Flags<SocketFlag, 2> */ size_t WriteBufferLen() const; - /** Called when there is something to be recieved for this socket + /** Called when there is something to be received for this socket * @return true on success, false to drop this socket */ virtual bool ProcessRead(); @@ -195,7 +193,7 @@ class CoreExport Socket : public Flags<SocketFlag, 2> */ virtual void ProcessError(); - /** Called with a line recieved from the socket + /** Called with a line received from the socket * @param buf The line * @return true to continue reading, false to drop the socket */ @@ -248,29 +246,27 @@ class CoreExport Pipe : public Socket class CoreExport ClientSocket : public Socket { protected: - /* Target host we're connected to */ - Anope::string TargetHost; - /* Target port we're connected to */ - int Port; - /* The host to bind to */ - Anope::string BindHost; + /* Sockaddrs for bindip (if there is one) */ + sockaddrs bindaddrs; + /* Sockaddrs for connection ip/port */ + sockaddrs conaddrs; public: /** Constructor - * @param nTargetHost The target host to connect to - * @param nPort The target port to connect to - * @param nBindHost The host to bind to for connecting + * @param TargetHost The target host to connect to + * @param Port The target port to connect to + * @param BindHost The host to bind to for connecting * @param nIPv6 true to use IPv6 * @param type The socket type, defaults to SOCK_STREAM */ - ClientSocket(const Anope::string &nTargetHost, int nPort, const Anope::string &nBindHost = "", bool nIPv6 = false, int type = SOCK_STREAM); + ClientSocket(const Anope::string &TargetHost, int Port, const Anope::string &BindHost = "", bool nIPv6 = false, int type = SOCK_STREAM); /** Default destructor */ virtual ~ClientSocket(); - /** Called with a line recieved from the socket + /** Called with a line received from the socket * @param buf The line * @return true to continue reading, false to drop the socket */ @@ -280,17 +276,15 @@ class CoreExport ClientSocket : public Socket class CoreExport ListenSocket : public Socket { protected: - /* Bind IP */ - Anope::string BindIP; - /* Port to bind to */ - int Port; + /* Sockaddrs for bindip/port */ + sockaddrs listenaddrs; public: /** Constructor - * @param bind The IP to bind to + * @param bindip The IP to bind to * @param port The port to listen on */ - ListenSocket(const Anope::string &bind, int port); + ListenSocket(const Anope::string &bindip, int port); /** Destructor */ @@ -306,16 +300,6 @@ class CoreExport ListenSocket : public Socket * @return true if the listen socket should remain alive */ virtual bool OnAccept(Socket *s); - - /** Get the bind IP for this socket - * @return the bind ip - */ - const Anope::string &GetBindIP() const; - - /** Get the port this socket is bound to - * @return The port - */ - int GetPort() const; }; #endif // SOCKET_H |
