From 5c544115bcad5a6d05dcecbb151cd674119a8e11 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Thu, 5 Mar 2015 19:16:28 +0100 Subject: [PATCH 2/3] DBusSocket refactoring - windows part --- dbus/dbus-spawn-win.c | 12 +++++----- dbus/dbus-sysdeps-util-win.c | 1 - dbus/dbus-sysdeps-win.c | 52 ++++++++++++++++++++++---------------------- 3 files changed, 32 insertions(+), 33 deletions(-) diff --git a/dbus/dbus-spawn-win.c b/dbus/dbus-spawn-win.c index 7da7a43..8b08c2c 100644 --- a/dbus/dbus-spawn-win.c +++ b/dbus/dbus-spawn-win.c @@ -77,8 +77,8 @@ struct DBusBabysitter char **envp; HANDLE child_handle; - int socket_to_babysitter; /* Connection to the babysitter thread */ - int socket_to_main; + DBusSocket socket_to_babysitter; /* Connection to the babysitter thread */ + DBusSocket socket_to_main; DBusWatchList *watches; DBusWatch *sitter_watch; @@ -171,10 +171,10 @@ close_socket_to_babysitter (DBusBabysitter *sitter) sitter->sitter_watch = NULL; } - if (sitter->socket_to_babysitter != -1) + if (sitter->socket_to_babysitter != INVALID_SOCKET) { _dbus_close_socket (sitter->socket_to_babysitter, NULL); - sitter->socket_to_babysitter = -1; + sitter->socket_to_babysitter = INVALID_SOCKET; } } @@ -198,10 +198,10 @@ _dbus_babysitter_unref (DBusBabysitter *sitter) { close_socket_to_babysitter (sitter); - if (sitter->socket_to_main != -1) + if (sitter->socket_to_main != INVALID_SOCKET) { _dbus_close_socket (sitter->socket_to_main, NULL); - sitter->socket_to_main = -1; + sitter->socket_to_main = INVALID_SOCKET; } PING(); diff --git a/dbus/dbus-sysdeps-util-win.c b/dbus/dbus-sysdeps-util-win.c index bda2283..e83c539 100644 --- a/dbus/dbus-sysdeps-util-win.c +++ b/dbus/dbus-sysdeps-util-win.c @@ -380,7 +380,6 @@ _dbus_stat(const DBusString *filename, const char *filename_c; WIN32_FILE_ATTRIBUTE_DATA wfad; char *lastdot; - DWORD rc; _DBUS_ASSERT_ERROR_IS_CLEAR (error); diff --git a/dbus/dbus-sysdeps-win.c b/dbus/dbus-sysdeps-win.c index 5025815..faa5280 100644 --- a/dbus/dbus-sysdeps-win.c +++ b/dbus/dbus-sysdeps-win.c @@ -52,7 +52,6 @@ #include "dbus-credentials.h" #include -#include #include #include @@ -376,7 +375,7 @@ _dbus_win_free_error_string (char *string) */ int -_dbus_read_socket (int fd, +_dbus_read_socket (DBusSocket fd, DBusString *buffer, int count) { @@ -446,7 +445,7 @@ _dbus_read_socket (int fd, * @returns the number of bytes written or -1 on error */ int -_dbus_write_socket (int fd, +_dbus_write_socket (DBusSocket fd, const DBusString *buffer, int start, int len) @@ -490,7 +489,7 @@ _dbus_write_socket (int fd, * @returns #FALSE if error set */ dbus_bool_t -_dbus_close_socket (int fd, +_dbus_close_socket (DBusSocket fd, DBusError *error) { _DBUS_ASSERT_ERROR_IS_CLEAR (error); @@ -580,7 +579,7 @@ _dbus_set_fd_nonblocking (int handle, * @returns total bytes written from both buffers, or -1 on error */ int -_dbus_write_socket_two (int fd, +_dbus_write_socket_two (DBusSocket fd, const DBusString *buffer1, int start1, int len1, @@ -646,7 +645,7 @@ _dbus_write_socket_two (int fd, dbus_bool_t _dbus_socket_is_invalid (int fd) { - return fd == INVALID_SOCKET ? TRUE : FALSE; + return fd == (int)INVALID_SOCKET ? TRUE : FALSE; } #if 0 @@ -1055,8 +1054,8 @@ failed: * @returns #FALSE on failure (if error is set) */ dbus_bool_t -_dbus_full_duplex_pipe (int *fd1, - int *fd2, +_dbus_full_duplex_pipe (DBusSocket *fd1, + DBusSocket *fd2, dbus_bool_t blocking, DBusError *error) { @@ -1507,7 +1506,7 @@ _dbus_connect_tcp_socket_with_nonce (const char *host, const char *noncefile, DBusError *error) { - int fd = -1, res; + SOCKET fd = INVALID_SOCKET, res; struct addrinfo hints; struct addrinfo *ai, *tmp; @@ -1579,7 +1578,7 @@ _dbus_connect_tcp_socket_with_nonce (const char *host, } freeaddrinfo(ai); - if (fd == -1) + if (fd == INVALID_SOCKET) { dbus_set_error (error, _dbus_error_from_errno (errno), @@ -1643,10 +1642,11 @@ _dbus_listen_tcp_socket (const char *host, const char *port, const char *family, DBusString *retport, - int **fds_p, + DBusSocket **fds_p, DBusError *error) { - int nlisten_fd = 0, *listen_fd = NULL, res, i, port_num = -1; + DBusSocket *listen_fd = NULL; + int nlisten_fd = 0, res, i, port_num = -1; struct addrinfo hints; struct addrinfo *ai, *tmp; @@ -1706,8 +1706,8 @@ _dbus_listen_tcp_socket (const char *host, tmp = ai; while (tmp) { - int fd = -1, *newlisten_fd; - if ((fd = socket (tmp->ai_family, SOCK_STREAM, 0)) == INVALID_SOCKET) + DBusSocket fd = INVALID_SOCKET, *newlisten_fd; + if ((fd = (DBusSocket)socket (tmp->ai_family, SOCK_STREAM, 0)) == INVALID_SOCKET) { DBUS_SOCKET_SET_ERRNO (); dbus_set_error (error, @@ -1849,10 +1849,10 @@ _dbus_listen_tcp_socket (const char *host, * @param listen_fd the listen file descriptor * @returns the connection fd of the client, or -1 on error */ -int -_dbus_accept (int listen_fd) +DBusSocket +_dbus_accept (DBusSocket listen_fd) { - int client_fd; + DBusSocket client_fd; retry: client_fd = accept (listen_fd, NULL, NULL); @@ -1873,7 +1873,7 @@ _dbus_accept (int listen_fd) dbus_bool_t -_dbus_send_credentials_socket (int handle, +_dbus_send_credentials_socket (DBusSocket handle, DBusError *error) { /* FIXME: for the session bus credentials shouldn't matter (?), but @@ -1950,7 +1950,7 @@ again: * @returns #TRUE on success */ dbus_bool_t -_dbus_read_credentials_socket (int handle, +_dbus_read_credentials_socket (DBusSocket handle, DBusCredentials *credentials, DBusError *error) { @@ -2263,7 +2263,7 @@ _dbus_generate_random_bytes (DBusString *str, int n_bytes) { int old_len; - char *p; + BYTE *p; HCRYPTPROV hprov; old_len = _dbus_string_get_length (str); @@ -2271,7 +2271,7 @@ _dbus_generate_random_bytes (DBusString *str, if (!_dbus_string_lengthen (str, n_bytes)) return FALSE; - p = _dbus_string_get_data_len (str, old_len, n_bytes); + p = (BYTE*)_dbus_string_get_data_len (str, old_len, n_bytes); if (!CryptAcquireContext (&hprov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) return FALSE; @@ -2307,17 +2307,17 @@ _dbus_get_tmpdir(void) { char *last_slash; - if (!GetTempPathA (sizeof (buf), buf)) + if (!GetTempPathA (sizeof (buf), (LPSTR)buf)) { _dbus_warn ("GetTempPath failed\n"); _dbus_abort (); } /* Drop terminating backslash or slash */ - last_slash = _mbsrchr (buf, '\\'); + last_slash = strrchr (buf, '\\'); if (last_slash > buf && last_slash[1] == '\0') last_slash[0] = '\0'; - last_slash = _mbsrchr (buf, '/'); + last_slash = strrchr (buf, '/'); if (last_slash > buf && last_slash[1] == '\0') last_slash[0] = '\0'; @@ -3292,12 +3292,12 @@ _dbus_get_install_root(char *prefix, int len) DWORD pathLength; char *lastSlash; SetLastError( 0 ); - pathLength = GetModuleFileNameA(_dbus_win_get_dll_hmodule(), prefix, len); + pathLength = GetModuleFileNameA(_dbus_win_get_dll_hmodule(), (LPSTR)prefix, len); if ( pathLength == 0 || GetLastError() != 0 ) { *prefix = '\0'; return FALSE; } - lastSlash = _mbsrchr(prefix, '\\'); + lastSlash = strrchr(prefix, '\\'); if (lastSlash == NULL) { *prefix = '\0'; return FALSE; -- 1.8.4.5