mirror of
https://github.com/git/git.git
synced 2024-11-28 04:23:30 +08:00
mingw: add network-wrappers for daemon
git-daemon requires some socket-functionality that is not yet supported in the Windows-port. This patch adds said functionality, and makes sure WSAStartup gets called by socket(), since it is the first network-call in git-daemon. Signed-off-by: Mike Pape <dotzenlabs@gmail.com> Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
ca209065f3
commit
772991af40
@ -1175,7 +1175,10 @@ int mingw_getnameinfo(const struct sockaddr *sa, socklen_t salen,
|
||||
int mingw_socket(int domain, int type, int protocol)
|
||||
{
|
||||
int sockfd;
|
||||
SOCKET s = WSASocket(domain, type, protocol, NULL, 0, 0);
|
||||
SOCKET s;
|
||||
|
||||
ensure_socket_initialization();
|
||||
s = WSASocket(domain, type, protocol, NULL, 0, 0);
|
||||
if (s == INVALID_SOCKET) {
|
||||
/*
|
||||
* WSAGetLastError() values are regular BSD error codes
|
||||
@ -1205,6 +1208,45 @@ int mingw_connect(int sockfd, struct sockaddr *sa, size_t sz)
|
||||
return connect(s, sa, sz);
|
||||
}
|
||||
|
||||
#undef bind
|
||||
int mingw_bind(int sockfd, struct sockaddr *sa, size_t sz)
|
||||
{
|
||||
SOCKET s = (SOCKET)_get_osfhandle(sockfd);
|
||||
return bind(s, sa, sz);
|
||||
}
|
||||
|
||||
#undef setsockopt
|
||||
int mingw_setsockopt(int sockfd, int lvl, int optname, void *optval, int optlen)
|
||||
{
|
||||
SOCKET s = (SOCKET)_get_osfhandle(sockfd);
|
||||
return setsockopt(s, lvl, optname, (const char*)optval, optlen);
|
||||
}
|
||||
|
||||
#undef listen
|
||||
int mingw_listen(int sockfd, int backlog)
|
||||
{
|
||||
SOCKET s = (SOCKET)_get_osfhandle(sockfd);
|
||||
return listen(s, backlog);
|
||||
}
|
||||
|
||||
#undef accept
|
||||
int mingw_accept(int sockfd1, struct sockaddr *sa, socklen_t *sz)
|
||||
{
|
||||
int sockfd2;
|
||||
|
||||
SOCKET s1 = (SOCKET)_get_osfhandle(sockfd1);
|
||||
SOCKET s2 = accept(s1, sa, sz);
|
||||
|
||||
/* convert into a file descriptor */
|
||||
if ((sockfd2 = _open_osfhandle(s2, O_RDWR|O_BINARY)) < 0) {
|
||||
int err = errno;
|
||||
closesocket(s2);
|
||||
return error("unable to make a socket file descriptor: %s",
|
||||
strerror(err));
|
||||
}
|
||||
return sockfd2;
|
||||
}
|
||||
|
||||
#undef rename
|
||||
int mingw_rename(const char *pold, const char *pnew)
|
||||
{
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
typedef int pid_t;
|
||||
typedef int uid_t;
|
||||
typedef int socklen_t;
|
||||
#define hstrerror strerror
|
||||
|
||||
#define S_IFLNK 0120000 /* Symbolic link */
|
||||
@ -47,6 +48,9 @@ typedef int uid_t;
|
||||
#define F_SETFD 2
|
||||
#define FD_CLOEXEC 0x1
|
||||
|
||||
#define EAFNOSUPPORT WSAEAFNOSUPPORT
|
||||
#define ECONNABORTED WSAECONNABORTED
|
||||
|
||||
struct passwd {
|
||||
char *pw_name;
|
||||
char *pw_gecos;
|
||||
@ -225,6 +229,18 @@ int mingw_socket(int domain, int type, int protocol);
|
||||
int mingw_connect(int sockfd, struct sockaddr *sa, size_t sz);
|
||||
#define connect mingw_connect
|
||||
|
||||
int mingw_bind(int sockfd, struct sockaddr *sa, size_t sz);
|
||||
#define bind mingw_bind
|
||||
|
||||
int mingw_setsockopt(int sockfd, int lvl, int optname, void *optval, int optlen);
|
||||
#define setsockopt mingw_setsockopt
|
||||
|
||||
int mingw_listen(int sockfd, int backlog);
|
||||
#define listen mingw_listen
|
||||
|
||||
int mingw_accept(int sockfd, struct sockaddr *sa, socklen_t *sz);
|
||||
#define accept mingw_accept
|
||||
|
||||
int mingw_rename(const char*, const char*);
|
||||
#define rename mingw_rename
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user