Commit bad53552 by Carlos Martín Nieto

netops: abstract away socket closing

Winsock wants us to use closesocket() instead of close(), so introduce
the gitno_close function, which does the right thing.

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
parent a2888919
...@@ -138,6 +138,18 @@ int gitno_send(GIT_SOCKET s, const char *msg, size_t len, int flags) ...@@ -138,6 +138,18 @@ int gitno_send(GIT_SOCKET s, const char *msg, size_t len, int flags)
return off; return off;
} }
#ifdef GIT_WIN32
int gitno_close(GIT_SOCKET s)
{
return closesocket(s) == SOCKET_ERROR ? -1 : 0;
}
#else
int gitno_close(GIT_SOCKET s)
{
return close(s);
}
#endif
int gitno_select_in(gitno_buffer *buf, long int sec, long int usec) int gitno_select_in(gitno_buffer *buf, long int sec, long int usec)
{ {
fd_set fds; fd_set fds;
......
...@@ -27,6 +27,7 @@ void gitno_consume_n(gitno_buffer *buf, size_t cons); ...@@ -27,6 +27,7 @@ void gitno_consume_n(gitno_buffer *buf, size_t cons);
int gitno_connect(const char *host, const char *port); int gitno_connect(const char *host, const char *port);
int gitno_send(GIT_SOCKET s, const char *msg, size_t len, int flags); int gitno_send(GIT_SOCKET s, const char *msg, size_t len, int flags);
int gitno_close(GIT_SOCKET s);
int gitno_select_in(gitno_buffer *buf, long int sec, long int usec); int gitno_select_in(gitno_buffer *buf, long int sec, long int usec);
int gitno_extract_host_and_port(char **host, char **port, const char *url, const char *default_port); int gitno_extract_host_and_port(char **host, char **port, const char *url, const char *default_port);
......
...@@ -362,7 +362,7 @@ static int http_close(git_transport *transport) ...@@ -362,7 +362,7 @@ static int http_close(git_transport *transport)
transport_http *t = (transport_http *) transport; transport_http *t = (transport_http *) transport;
int error; int error;
error = close(t->socket); error = gitno_close(t->socket);
if (error < 0) if (error < 0)
return git__throw(GIT_EOSERR, "Failed to close the socket: %s", strerror(errno)); return git__throw(GIT_EOSERR, "Failed to close the socket: %s", strerror(errno));
......
...@@ -505,15 +505,18 @@ static int git_download_pack(char **out, git_transport *transport, git_repositor ...@@ -505,15 +505,18 @@ static int git_download_pack(char **out, git_transport *transport, git_repositor
static int git_close(git_transport *transport) static int git_close(git_transport *transport)
{ {
transport_git *t = (transport_git*) transport; transport_git *t = (transport_git*) transport;
int s = t->socket;
int error; int error;
/* Can't do anything if there's an error, so don't bother checking */ /* Can't do anything if there's an error, so don't bother checking */
git_pkt_send_flush(s); git_pkt_send_flush(t->socket);
error = close(s); error = gitno_close(t->socket);
if (error < 0) if (error < 0)
error = git__throw(GIT_EOSERR, "Failed to close socket"); error = git__throw(GIT_EOSERR, "Failed to close socket");
#ifdef GIT_WIN32
WSACleanup();
#endif
return error; return error;
} }
...@@ -528,10 +531,6 @@ static void git_free(git_transport *transport) ...@@ -528,10 +531,6 @@ static void git_free(git_transport *transport)
git_pkt_free(p); git_pkt_free(p);
} }
#ifdef GIT_WIN32
WSACleanup();
#endif
git_vector_free(refs); git_vector_free(refs);
free(t->heads); free(t->heads);
free(t->parent.url); free(t->parent.url);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment