#include <stdio.h>
static dbus_bool_t
-do_check_nonce (int fd, const DBusString *nonce, DBusError *error)
+do_check_nonce (DBusSocket fd, const DBusString *nonce, DBusError *error)
{
DBusString buffer;
DBusString p;
_dbus_assert (noncefile != NULL);
if (!_dbus_string_init (&nonce))
- return -1;
+ return _dbus_socket_get_invalid ();
//PENDING(kdab): set better errors
if (_dbus_read_nonce (_dbus_noncefile_get_path(noncefile), &nonce, NULL) != TRUE)
- return -1;
+ return _dbus_socket_get_invalid ();
fd = _dbus_accept (listen_fd);
- if (_dbus_socket_is_invalid (fd))
+ if (!DBUS_SOCKET_IS_VALID (fd))
return fd;
if (do_check_nonce(fd, &nonce, NULL) != TRUE) {
_dbus_verbose ("nonce check failed. Closing socket.\n");
_dbus_close_socket(fd, NULL);
- return -1;
+ return _dbus_socket_get_invalid ();
}
return fd;
* indicate whether the server accepted the nonce.
*/
dbus_bool_t
-_dbus_send_nonce (int fd, const DBusString *noncefile, DBusError *error)
+_dbus_send_nonce (DBusSocket fd,
+ const DBusString *noncefile,
+ DBusError *error)
{
dbus_bool_t read_result;
int send_result;
// client
-dbus_bool_t _dbus_send_nonce (int fd,
+dbus_bool_t _dbus_send_nonce (DBusSocket fd,
const DBusString *noncefile,
DBusError *error);
_dbus_string_free (&address);
- client_fd = -1;
+ DBUS_SOCKET_INVALIDATE (client_fd);
server_transport = _dbus_transport_new_for_socket (server_fd,
&server->guid_hex, NULL);
return NULL;
}
- server_fd = -1;
+ DBUS_SOCKET_INVALIDATE (server_fd);
if (!_dbus_transport_set_auth_mechanisms (server_transport,
(const char**) server->auth_mechanisms))
/* Return value is just for memory, not other failures. */
static dbus_bool_t
handle_new_client_fd_and_unlock (DBusServer *server,
- int client_fd)
+ DBusSocket client_fd)
{
DBusConnection *connection;
DBusTransport *transport;
DBusNewConnectionFunction new_connection_function;
void *new_connection_data;
- _dbus_verbose ("Creating new client connection with fd %d\n", client_fd);
+ _dbus_verbose ("Creating new client connection with fd %" DBUS_SOCKET_FORMAT "\n",
+ DBUS_SOCKET_PRINTABLE (client_fd));
HAVE_LOCK_CHECK (server);
saved_errno = _dbus_save_socket_errno ();
- if (client_fd == DBUS_SOCKET_INVALID)
+ if (!DBUS_SOCKET_IS_VALID (client_fd))
{
/* EINTR handled for us */
}
_dbus_close_socket (socket_server->fds[i], NULL);
- socket_server->fds[i] = DBUS_SOCKET_INVALID;
+ DBUS_SOCKET_INVALIDATE (socket_server->fds[i]);
}
if (socket_server->socket_name != NULL)
}
else if (strcmp (method, "systemd") == 0)
{
- int i, n, *fds;
+ int i, n;
+ DBusSocket *fds;
DBusString address;
n = _dbus_listen_systemd_sockets (&fds, error);
* @returns #FALSE if error is set
*/
dbus_bool_t
-_dbus_close_socket (int fd,
+_dbus_close_socket (DBusSocket fd,
DBusError *error)
{
return _dbus_close (fd, error);
* @returns number of bytes appended to the string
*/
int
-_dbus_read_socket (int fd,
+_dbus_read_socket (DBusSocket fd,
DBusString *buffer,
int count)
{
* @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)
}
int
-_dbus_write_socket_with_unix_fds(int fd,
+_dbus_write_socket_with_unix_fds(DBusSocket fd,
const DBusString *buffer,
int start,
int len,
}
int
-_dbus_write_socket_with_unix_fds_two(int fd,
+_dbus_write_socket_with_unix_fds_two(DBusSocket fd,
const DBusString *buffer1,
int start1,
int len1,
* @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,
* @returns the number of file descriptors
*/
int
-_dbus_listen_systemd_sockets (int **fds,
- DBusError *error)
+_dbus_listen_systemd_sockets (DBusSocket **fds,
+ DBusError *error)
{
#ifdef HAVE_SYSTEMD
int r, n;
int fd;
- int *new_fds;
+ DBusSocket *new_fds;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
/* OK, the file descriptors are all good, so let's take posession of
them then. */
- new_fds = dbus_new (int, n);
+ new_fds = dbus_new (DBusSocket, n);
if (!new_fds)
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY,
* @param error return location for error code
* @returns connection file descriptor or -1 on error
*/
-int
+DBusSocket
_dbus_connect_tcp_socket (const char *host,
const char *port,
const char *family,
return _dbus_connect_tcp_socket_with_nonce (host, port, family, (const char*)NULL, error);
}
-int
+DBusSocket
_dbus_connect_tcp_socket_with_nonce (const char *host,
const char *port,
const char *family,
const char *port,
const char *family,
DBusString *retport,
- int **fds_p,
+ DBusSocket **fds_p,
DBusError *error)
{
int saved_errno;
- int nlisten_fd = 0, *listen_fd = NULL, res, i;
+ int nlisten_fd = 0, res, i;
+ DBusSocket *listen_fd = NULL;
struct addrinfo hints;
struct addrinfo *ai, *tmp;
unsigned int reuseaddr;
tmp = ai;
while (tmp)
{
- int fd = -1, *newlisten_fd, tcp_nodelay_on;
+ int fd = -1, tcp_nodelay_on;
+ DBusSocket *newlisten_fd;
+
if (!_dbus_open_socket (&fd, tmp->ai_family, SOCK_STREAM, 0, error))
{
_DBUS_ASSERT_ERROR_IS_SET(error);
goto failed;
}
- newlisten_fd = dbus_realloc(listen_fd, sizeof(int)*(nlisten_fd+1));
+ newlisten_fd = dbus_realloc(listen_fd, sizeof(DBusSocket)*(nlisten_fd+1));
if (!newlisten_fd)
{
saved_errno = errno;
* @returns #TRUE if the byte was sent
*/
dbus_bool_t
-_dbus_send_credentials_socket (int server_fd,
+_dbus_send_credentials_socket (DBusSocket server_fd,
DBusError *error)
{
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
* @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;
struct sockaddr addr;
socklen_t addrlen;
#ifdef HAVE_ACCEPT4
*
*/
dbus_bool_t
-_dbus_socket_can_pass_unix_fd(int fd) {
-
+_dbus_socket_can_pass_unix_fd (DBusSocket fd)
+{
#ifdef SCM_RIGHTS
union {
struct sockaddr sa;
* @param error return location for error code
*/
dbus_bool_t
-_dbus_append_address_from_socket (int fd,
+_dbus_append_address_from_socket (DBusSocket fd,
DBusString *address,
DBusError *error)
{
char *const argv[],
DBusError *error);
-int _dbus_listen_systemd_sockets (int **fd,
- DBusError *error);
+int _dbus_listen_systemd_sockets (DBusSocket **fd,
+ DBusError *error);
dbus_bool_t _dbus_read_credentials (int client_fd,
DBusCredentials *credentials,
DBUS_PRIVATE_EXPORT
void _dbus_close_all (void);
-dbus_bool_t _dbus_append_address_from_socket (int fd,
+dbus_bool_t _dbus_append_address_from_socket (DBusSocket fd,
DBusString *address,
DBusError *error);
* @param error return location for error code
* @returns connection file descriptor or -1 on error
*/
-int
+DBusSocket
_dbus_connect_tcp_socket (const char *host,
const char *port,
const char *family,
return _dbus_connect_tcp_socket_with_nonce (host, port, family, (const char*)NULL, error);
}
-int
+DBusSocket
_dbus_connect_tcp_socket_with_nonce (const char *host,
const char *port,
const char *family,
dbus_bool_t _dbus_socket_is_invalid (DBusSocket fd);
-int _dbus_connect_tcp_socket (const char *host,
- const char *port,
- const char *family,
- DBusError *error);
-int _dbus_connect_tcp_socket_with_nonce (const char *host,
- const char *port,
- const char *family,
- const char *noncefile,
- DBusError *error);
+DBusSocket _dbus_connect_tcp_socket (const char *host,
+ const char *port,
+ const char *family,
+ DBusError *error);
+DBusSocket _dbus_connect_tcp_socket_with_nonce (const char *host,
+ const char *port,
+ const char *family,
+ const char *noncefile,
+ DBusError *error);
int _dbus_listen_tcp_socket (const char *host,
const char *port,
const char *family,