summaryrefslogtreecommitdiff
path: root/src/SFML/Network
diff options
context:
space:
mode:
Diffstat (limited to 'src/SFML/Network')
-rw-r--r--src/SFML/Network/Ftp.cpp2
-rw-r--r--src/SFML/Network/Http.cpp3
-rw-r--r--src/SFML/Network/IpAddress.cpp2
-rw-r--r--src/SFML/Network/Packet.cpp3
-rw-r--r--src/SFML/Network/Socket.cpp2
-rw-r--r--src/SFML/Network/SocketImpl.hpp2
-rw-r--r--src/SFML/Network/SocketSelector.cpp2
-rw-r--r--src/SFML/Network/TcpListener.cpp2
-rw-r--r--src/SFML/Network/TcpSocket.cpp51
-rw-r--r--src/SFML/Network/UdpSocket.cpp2
-rw-r--r--src/SFML/Network/Unix/SocketImpl.cpp2
-rw-r--r--src/SFML/Network/Unix/SocketImpl.hpp2
-rw-r--r--src/SFML/Network/Win32/SocketImpl.cpp2
-rw-r--r--src/SFML/Network/Win32/SocketImpl.hpp2
14 files changed, 55 insertions, 24 deletions
diff --git a/src/SFML/Network/Ftp.cpp b/src/SFML/Network/Ftp.cpp
index 0f4049e..44a03b8 100644
--- a/src/SFML/Network/Ftp.cpp
+++ b/src/SFML/Network/Ftp.cpp
@@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
+// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
diff --git a/src/SFML/Network/Http.cpp b/src/SFML/Network/Http.cpp
index df3ebb4..68737f4 100644
--- a/src/SFML/Network/Http.cpp
+++ b/src/SFML/Network/Http.cpp
@@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
+// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
@@ -107,7 +107,6 @@ std::string Http::Request::prepare() const
std::string method;
switch (m_method)
{
- default:
case Get: method = "GET"; break;
case Post: method = "POST"; break;
case Head: method = "HEAD"; break;
diff --git a/src/SFML/Network/IpAddress.cpp b/src/SFML/Network/IpAddress.cpp
index 0459091..19f0840 100644
--- a/src/SFML/Network/IpAddress.cpp
+++ b/src/SFML/Network/IpAddress.cpp
@@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
+// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
diff --git a/src/SFML/Network/Packet.cpp b/src/SFML/Network/Packet.cpp
index 31fe259..2c5d0e0 100644
--- a/src/SFML/Network/Packet.cpp
+++ b/src/SFML/Network/Packet.cpp
@@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
+// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
@@ -37,6 +37,7 @@ namespace sf
////////////////////////////////////////////////////////////
Packet::Packet() :
m_readPos(0),
+m_sendPos(0),
m_isValid(true)
{
diff --git a/src/SFML/Network/Socket.cpp b/src/SFML/Network/Socket.cpp
index a74aa10..58ff16a 100644
--- a/src/SFML/Network/Socket.cpp
+++ b/src/SFML/Network/Socket.cpp
@@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
+// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
diff --git a/src/SFML/Network/SocketImpl.hpp b/src/SFML/Network/SocketImpl.hpp
index fbe45bc..423787e 100644
--- a/src/SFML/Network/SocketImpl.hpp
+++ b/src/SFML/Network/SocketImpl.hpp
@@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
+// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
diff --git a/src/SFML/Network/SocketSelector.cpp b/src/SFML/Network/SocketSelector.cpp
index 8b521bb..31e82d8 100644
--- a/src/SFML/Network/SocketSelector.cpp
+++ b/src/SFML/Network/SocketSelector.cpp
@@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
+// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
diff --git a/src/SFML/Network/TcpListener.cpp b/src/SFML/Network/TcpListener.cpp
index 78f7f43..7a68707 100644
--- a/src/SFML/Network/TcpListener.cpp
+++ b/src/SFML/Network/TcpListener.cpp
@@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
+// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
diff --git a/src/SFML/Network/TcpSocket.cpp b/src/SFML/Network/TcpSocket.cpp
index ac6d6b9..5a032ef 100644
--- a/src/SFML/Network/TcpSocket.cpp
+++ b/src/SFML/Network/TcpSocket.cpp
@@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
+// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
@@ -219,6 +219,18 @@ void TcpSocket::disconnect()
////////////////////////////////////////////////////////////
Socket::Status TcpSocket::send(const void* data, std::size_t size)
{
+ if (!isBlocking())
+ err() << "Warning: Partial sends might not be handled properly." << std::endl;
+
+ std::size_t sent;
+
+ return send(data, size, sent);
+}
+
+
+////////////////////////////////////////////////////////////
+Socket::Status TcpSocket::send(const void* data, std::size_t size, std::size_t& sent)
+{
// Check the parameters
if (!data || (size == 0))
{
@@ -227,16 +239,22 @@ Socket::Status TcpSocket::send(const void* data, std::size_t size)
}
// Loop until every byte has been sent
- int sent = 0;
- int sizeToSend = static_cast<int>(size);
- for (int length = 0; length < sizeToSend; length += sent)
+ int result = 0;
+ for (sent = 0; sent < size; sent += result)
{
// Send a chunk of data
- sent = ::send(getHandle(), static_cast<const char*>(data) + length, sizeToSend - length, flags);
+ result = ::send(getHandle(), static_cast<const char*>(data) + sent, size - sent, flags);
// Check for errors
- if (sent < 0)
- return priv::SocketImpl::getErrorStatus();
+ if (result < 0)
+ {
+ Status status = priv::SocketImpl::getErrorStatus();
+
+ if ((status == NotReady) && sent)
+ return Partial;
+
+ return status;
+ }
}
return Done;
@@ -294,17 +312,30 @@ Socket::Status TcpSocket::send(Packet& packet)
// First convert the packet size to network byte order
Uint32 packetSize = htonl(static_cast<Uint32>(size));
-
+
// Allocate memory for the data block to send
std::vector<char> blockToSend(sizeof(packetSize) + size);
-
+
// Copy the packet size and data into the block to send
std::memcpy(&blockToSend[0], &packetSize, sizeof(packetSize));
if (size > 0)
std::memcpy(&blockToSend[0] + sizeof(packetSize), data, size);
// Send the data block
- return send(&blockToSend[0], blockToSend.size());
+ std::size_t sent;
+ Status status = send(&blockToSend[0] + packet.m_sendPos, blockToSend.size() - packet.m_sendPos, sent);
+
+ // In the case of a partial send, record the location to resume from
+ if (status == Partial)
+ {
+ packet.m_sendPos += sent;
+ }
+ else if (status == Done)
+ {
+ packet.m_sendPos = 0;
+ }
+
+ return status;
}
diff --git a/src/SFML/Network/UdpSocket.cpp b/src/SFML/Network/UdpSocket.cpp
index af56f5d..ffa1494 100644
--- a/src/SFML/Network/UdpSocket.cpp
+++ b/src/SFML/Network/UdpSocket.cpp
@@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
+// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
diff --git a/src/SFML/Network/Unix/SocketImpl.cpp b/src/SFML/Network/Unix/SocketImpl.cpp
index a36e617..9a33d90 100644
--- a/src/SFML/Network/Unix/SocketImpl.cpp
+++ b/src/SFML/Network/Unix/SocketImpl.cpp
@@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
+// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
diff --git a/src/SFML/Network/Unix/SocketImpl.hpp b/src/SFML/Network/Unix/SocketImpl.hpp
index 8a3f29f..c54c55f 100644
--- a/src/SFML/Network/Unix/SocketImpl.hpp
+++ b/src/SFML/Network/Unix/SocketImpl.hpp
@@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
+// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
diff --git a/src/SFML/Network/Win32/SocketImpl.cpp b/src/SFML/Network/Win32/SocketImpl.cpp
index 3fc6bb2..0f19842 100644
--- a/src/SFML/Network/Win32/SocketImpl.cpp
+++ b/src/SFML/Network/Win32/SocketImpl.cpp
@@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
+// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
diff --git a/src/SFML/Network/Win32/SocketImpl.hpp b/src/SFML/Network/Win32/SocketImpl.hpp
index 8178c7c..f6cabaf 100644
--- a/src/SFML/Network/Win32/SocketImpl.hpp
+++ b/src/SFML/Network/Win32/SocketImpl.hpp
@@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
+// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.