From 5ced910478c16c8acb93c6f9bfc65886178e7dbe Mon Sep 17 00:00:00 2001 From: brain Date: Mon, 23 May 2005 18:03:04 +0000 Subject: Tidied up some socket stuff into userrec git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@1476 e03df62e-2008-0410-955e-edbf42e46eb7 --- include/users.h | 8 ++++++++ src/commands.cpp | 11 ++--------- src/inspircd.cpp | 8 +++----- src/users.cpp | 15 ++++++++++++++- 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/include/users.h b/include/users.h index 2dda51984..c3a9e79b5 100644 --- a/include/users.h +++ b/include/users.h @@ -254,6 +254,10 @@ class userrec : public connection */ bool HasPermission(char* command); + /** Calls read() to read some data for this user using their fd. + */ + int ReadData(void* buffer, size_t size); + /** This method adds data to the buffer of the user. * The buffer can grow to any size within limits of the available memory, * managed by the size of a std::string, however if any individual line in @@ -311,6 +315,10 @@ class userrec : public connection /** Returns the list of channels this user has been invited to but has not yet joined. */ InvitedList* GetInviteList(); + + /** Shuts down and closes the user's socket + */ + void CloseSocket(); }; /** A lightweight userrec used by WHOWAS diff --git a/src/commands.cpp b/src/commands.cpp index 5531af3af..5466a6258 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -303,13 +303,7 @@ void handle_restart(char **parameters, int pcnt, userrec *user) sleep(1); for (int i = 0; i < 65536; i++) { - int on = 1; - struct linger linger = { 0 }; - setsockopt(i, SOL_SOCKET, SO_REUSEADDR, (const char*)&on, sizeof(on)); - linger.l_onoff = 1; - linger.l_linger = 1; - setsockopt(i, SOL_SOCKET, SO_LINGER, (const char*)&linger,sizeof(linger)); - Blocking(i); + shutdown(i,2); close(i); } sleep(2); @@ -950,8 +944,7 @@ void handle_quit(char **parameters, int pcnt, userrec *user) log(DEBUG,"epoll: List deletion failure!"); } #endif - shutdown(user->fd,2); - close(user->fd); + user->CloseSocket(); } if (iter != clientlist.end()) diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 132832bc1..c0603db59 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -1107,8 +1107,7 @@ void kill_link(userrec *user,const char* r) log(DEBUG,"epoll: List deletion failure!"); } #endif - shutdown(user->fd,2); - close(user->fd); + user->CloseSocket(); } // this must come before the WriteOpers so that it doesnt try to fill their buffer with anything @@ -1182,8 +1181,7 @@ void kill_link_silent(userrec *user,const char* r) log(DEBUG,"epoll: List deletion failure!"); } #endif - shutdown(user->fd,2); - close(user->fd); + user->CloseSocket(); } if (user->registered == 7) { @@ -3147,7 +3145,7 @@ int InspIRCd(char** argv, int argc) FOREACH_RESULT(OnRawSocketRead(cu->fd,data,65535,result2)); if (!MOD_RESULT) { - result = read(cu->fd, data, 65535); + result = cu->ReadData(data, 65535); } else result = result2; log(DEBUG,"Read result: %d",result); diff --git a/src/users.cpp b/src/users.cpp index 48bb12430..493cbbade 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -59,7 +59,11 @@ userrec::userrec() invites.clear(); } - +void userrec::CloseSocket() +{ + shutdown(this->fd); + close(this->fd); +} char* userrec::GetFullHost() { @@ -67,6 +71,15 @@ char* userrec::GetFullHost() return result; } +int userrec::ReadData(void* buffer, size_t size) +{ + if (this->fd > -1) + { + return read(this->fd, buffer, size) + } + else return 0; +} + char* userrec::GetFullRealHost() { -- cgit v1.2.3