diff options
author | faketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-01-31 01:38:18 +0100 |
---|---|---|
committer | faketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-01-31 01:38:18 +0100 |
commit | c142424571a3744e8b68ec9746eaa05505c03af5 (patch) | |
tree | 9a8950e671cafbe4eddc096cdc648d7876c1b1de /WebServer/Socket.cpp | |
parent | Replaced most FILE operations with a cFile object (diff) | |
download | cuberite-c142424571a3744e8b68ec9746eaa05505c03af5.tar cuberite-c142424571a3744e8b68ec9746eaa05505c03af5.tar.gz cuberite-c142424571a3744e8b68ec9746eaa05505c03af5.tar.bz2 cuberite-c142424571a3744e8b68ec9746eaa05505c03af5.tar.lz cuberite-c142424571a3744e8b68ec9746eaa05505c03af5.tar.xz cuberite-c142424571a3744e8b68ec9746eaa05505c03af5.tar.zst cuberite-c142424571a3744e8b68ec9746eaa05505c03af5.zip |
Diffstat (limited to 'WebServer/Socket.cpp')
-rw-r--r-- | WebServer/Socket.cpp | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/WebServer/Socket.cpp b/WebServer/Socket.cpp index ec3c9a5c7..e2a5179f3 100644 --- a/WebServer/Socket.cpp +++ b/WebServer/Socket.cpp @@ -118,11 +118,20 @@ Socket& Socket::operator=(Socket& o) { return *this;
}
-void Socket::Close() {
+void Socket::Close( bool a_WaitSend /* = false */ )
+{
if( s_ )
{
- closesocket(s_);
- s_ = 0;
+ if( a_WaitSend )
+ {
+ assert( shutdown(s_, SD_SEND ) == 0 );
+ char c;
+ while( recv(s_, &c, 1, 0 ) != 0 )
+ {}
+ }
+
+ closesocket(s_);
+ s_ = 0;
}
}
@@ -135,12 +144,25 @@ std::string Socket::ReceiveLine() { {
return "";
}
-
ret += r;
if (r == '\n') return ret;
}
}
+std::string Socket::ReceiveBytes( unsigned int a_Length ) {
+ std::string ret;
+ while( ret.size() < a_Length ) {
+ char r;
+
+ if (recv(s_, &r, 1, 0) <= 0 )
+ {
+ return "";
+ }
+ ret += r;
+ }
+ return ret;
+}
+
void Socket::SendLine(std::string s) {
s += '\n';
if( send(s_,s.c_str(),s.length(),MSG_NOSIGNAL) <= 0 )
|