aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLee Salzman <[email protected]>2012-09-18 16:38:10 +0300
committerLee Salzman <[email protected]>2012-09-18 16:38:10 +0300
commit0e0ace781b3d41c08d310e678f4e08e323a6a3b8 (patch)
treec1bfa74351a74ab5b00ec2a5fe9e74d8b415a1a7
parent74d4c4a88fb274b068352512d8d0dfa3ff819d56 (diff)
downloadenet-0e0ace781b3d41c08d310e678f4e08e323a6a3b8.tar.gz
enet-0e0ace781b3d41c08d310e678f4e08e323a6a3b8.zip
merging some things from Ryan C. Gordon (icculus):
enet_socket_connect() shouldn't fail with non-blocking sockets. Removed unused variable. Sanity check for possible NULL dereference reported by clang's static…analysis. Added an interface to shutdown(). Fixed typo in the comments.
-rw-r--r--include/enet/enet.h8
-rw-r--r--peer.c3
-rw-r--r--protocol.c3
-rw-r--r--unix.c13
-rw-r--r--win32.c13
5 files changed, 36 insertions, 4 deletions
diff --git a/include/enet/enet.h b/include/enet/enet.h
index 3958d1c..b3ad438 100644
--- a/include/enet/enet.h
+++ b/include/enet/enet.h
@@ -55,6 +55,13 @@ typedef enum _ENetSocketOption
ENET_SOCKOPT_SNDTIMEO = 7
} ENetSocketOption;
+typedef enum _ENetSocketShutdown
+{
+ ENET_SOCKET_SHUTDOWN_READ = 0,
+ ENET_SOCKET_SHUTDOWN_WRITE = 1,
+ ENET_SOCKET_SHUTDOWN_READ_WRITE = 2
+} ENetSocketShutdown;
+
enum
{
ENET_HOST_ANY = 0, /**< specifies the default server host */
@@ -460,6 +467,7 @@ ENET_API int enet_socket_send (ENetSocket, const ENetAddress *, const ENe
ENET_API int enet_socket_receive (ENetSocket, ENetAddress *, ENetBuffer *, size_t);
ENET_API int enet_socket_wait (ENetSocket, enet_uint32 *, enet_uint32);
ENET_API int enet_socket_set_option (ENetSocket, ENetSocketOption, int);
+ENET_API int enet_socket_shutdown (ENetSocket, ENetSocketShutdown);
ENET_API void enet_socket_destroy (ENetSocket);
ENET_API int enet_socketset_select (ENetSocket, ENetSocketSet *, ENetSocketSet *, enet_uint32);
diff --git a/peer.c b/peer.c
index 56a93f6..a86d793 100644
--- a/peer.c
+++ b/peer.c
@@ -25,7 +25,7 @@
the mean round trip time measured over the interval, then the throttle probability
is decreased to limit traffic by an amount specified in the deceleration parameter, which
is a ratio to the ENET_PEER_PACKET_THROTTLE_SCALE constant. When the throttle has
- a value of ENET_PEER_PACKET_THROTTLE_SCALE, on unreliable packets are dropped by
+ a value of ENET_PEER_PACKET_THROTTLE_SCALE, no unreliable packets are dropped by
ENet, and so 100% of all unreliable packets will be sent. When the throttle has a
value of 0, all unreliable packets are dropped by ENet, and so 0% of all unreliable
packets will be sent. Intermediate values for the throttle represent intermediate
@@ -751,7 +751,6 @@ enet_peer_dispatch_incoming_unreliable_commands (ENetPeer * peer, ENetChannel *
void
enet_peer_dispatch_incoming_reliable_commands (ENetPeer * peer, ENetChannel * channel)
{
- enet_uint16 oldReliableSequenceNumber = channel -> incomingReliableSequenceNumber;
ENetListIterator currentCommand;
for (currentCommand = enet_list_begin (& channel -> incomingReliableCommands);
diff --git a/protocol.c b/protocol.c
index 1ebf797..2563513 100644
--- a/protocol.c
+++ b/protocol.c
@@ -210,6 +210,9 @@ enet_protocol_remove_sent_reliable_command (ENetPeer * peer, enet_uint16 reliabl
wasSent = 0;
}
+ if (outgoingCommand == NULL)
+ return ENET_PROTOCOL_COMMAND_NONE;
+
if (channelID < peer -> channelCount)
{
ENetChannel * channel = & peer -> channels [channelID];
diff --git a/unix.c b/unix.c
index 7bbe77a..d425b4b 100644
--- a/unix.c
+++ b/unix.c
@@ -254,6 +254,7 @@ int
enet_socket_connect (ENetSocket socket, const ENetAddress * address)
{
struct sockaddr_in sin;
+ int result;
memset (& sin, 0, sizeof (struct sockaddr_in));
@@ -261,7 +262,11 @@ enet_socket_connect (ENetSocket socket, const ENetAddress * address)
sin.sin_port = ENET_HOST_TO_NET_16 (address -> port);
sin.sin_addr.s_addr = address -> host;
- return connect (socket, (struct sockaddr *) & sin, sizeof (struct sockaddr_in));
+ result = connect (socket, (struct sockaddr *) & sin, sizeof (struct sockaddr_in));
+ if (result == -1 && errno == EINPROGRESS)
+ return 0;
+
+ return result;
}
ENetSocket
@@ -287,6 +292,12 @@ enet_socket_accept (ENetSocket socket, ENetAddress * address)
return result;
}
+int
+enet_socket_shutdown (ENetSocket socket, ENetSocketShutdown how)
+{
+ return shutdown (socket, (int) how);
+}
+
void
enet_socket_destroy (ENetSocket socket)
{
diff --git a/win32.c b/win32.c
index 708d306..850d8a3 100644
--- a/win32.c
+++ b/win32.c
@@ -184,6 +184,7 @@ int
enet_socket_connect (ENetSocket socket, const ENetAddress * address)
{
struct sockaddr_in sin;
+ int result;
memset (& sin, 0, sizeof (struct sockaddr_in));
@@ -191,7 +192,11 @@ enet_socket_connect (ENetSocket socket, const ENetAddress * address)
sin.sin_port = ENET_HOST_TO_NET_16 (address -> port);
sin.sin_addr.s_addr = address -> host;
- return connect (socket, (struct sockaddr *) & sin, sizeof (struct sockaddr_in)) == SOCKET_ERROR ? -1 : 0;
+ result = connect (socket, (struct sockaddr *) & sin, sizeof (struct sockaddr_in));
+ if (result == SOCKET_ERROR && WSAGetLastError () != EWOULDBLOCK)
+ return -1;
+
+ return 0;
}
ENetSocket
@@ -217,6 +222,12 @@ enet_socket_accept (ENetSocket socket, ENetAddress * address)
return result;
}
+int
+enet_socket_shutdown (ENetSocket socket, ENetSocketShutdown how)
+{
+ return shutdown (socket, (int) how) == SOCKET_ERROR ? -1 : 0;
+}
+
void
enet_socket_destroy (ENetSocket socket)
{