Skip to content

Commit 91e11cc

Browse files
committed
sfTcpListener_accept now returns a null pointer when it fails
1 parent 12b7c5a commit 91e11cc

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

include/SFML/Network/TcpListener.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ CSFML_NETWORK_API sfSocketStatus sfTcpListener_listen(sfTcpListener* listener, u
112112
/// If the socket is in blocking mode, this function will
113113
/// not return until a connection is actually received.
114114
///
115+
/// The \a connected argument points to a valid sfTcpSocket pointer
116+
/// in case of success (the function returns sfSocketDone), it points
117+
/// to a NULL pointer otherwise.
118+
///
115119
/// \param listener TCP listener object
116120
/// \param connected Socket that will hold the new connection
117121
///

src/SFML/Network/TcpListener.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,13 @@ sfSocketStatus sfTcpListener_accept(sfTcpListener* listener, sfTcpSocket** conne
8282
CSFML_CHECK_RETURN(connected, sfSocketError);
8383

8484
*connected = new sfTcpSocket;
85-
return static_cast<sfSocketStatus>(listener->This.accept((*connected)->This));
85+
sfSocketStatus status = static_cast<sfSocketStatus>(listener->This.accept((*connected)->This));
86+
87+
if (status != sfSocketDone)
88+
{
89+
delete *connected;
90+
*connected = NULL;
91+
}
92+
93+
return status;
8694
}

0 commit comments

Comments
 (0)