Compare commits
2 Commits
adc_client
...
0.3.x-stab
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c9f32c8f7f | ||
|
|
4c94753469 |
@@ -119,6 +119,7 @@ void sid_pool_destroy(struct sid_pool* pool)
|
|||||||
|
|
||||||
sid_t sid_alloc(struct sid_pool* pool, struct hub_user* user)
|
sid_t sid_alloc(struct sid_pool* pool, struct hub_user* user)
|
||||||
{
|
{
|
||||||
|
sid_t n;
|
||||||
if (pool->count >= (pool->max - pool->min))
|
if (pool->count >= (pool->max - pool->min))
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_SID
|
#ifdef DEBUG_SID
|
||||||
@@ -127,7 +128,7 @@ sid_t sid_alloc(struct sid_pool* pool, struct hub_user* user)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sid_t n = (++pool->count);
|
n = (++pool->count);
|
||||||
for (; (pool->map[n % pool->max]); n++) ;
|
for (; (pool->map[n % pool->max]); n++) ;
|
||||||
|
|
||||||
#ifdef DEBUG_SID
|
#ifdef DEBUG_SID
|
||||||
|
|||||||
@@ -426,11 +426,12 @@ static int command_broadcast(struct hub_info* hub, struct hub_user* user, struct
|
|||||||
char from_sid[5];
|
char from_sid[5];
|
||||||
char buffer[128];
|
char buffer[128];
|
||||||
size_t recipients = 0;
|
size_t recipients = 0;
|
||||||
|
struct hub_user* target;
|
||||||
|
|
||||||
memcpy(from_sid, sid_to_string(user->id.sid), sizeof(from_sid));
|
memcpy(from_sid, sid_to_string(user->id.sid), sizeof(from_sid));
|
||||||
memcpy(pm_flag + 2, from_sid, sizeof(from_sid));
|
memcpy(pm_flag + 2, from_sid, sizeof(from_sid));
|
||||||
|
|
||||||
struct hub_user* target = (struct hub_user*) list_get_first(hub->users->list);
|
target = (struct hub_user*) list_get_first(hub->users->list);
|
||||||
while (target)
|
while (target)
|
||||||
{
|
{
|
||||||
if (target != user)
|
if (target != user)
|
||||||
|
|||||||
109
src/includes.h
Normal file
109
src/includes.h
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
/*
|
||||||
|
* uhub - A tiny ADC p2p connection hub
|
||||||
|
* Copyright (C) 2007-2010, Jan Vidar Krey
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef HAVE_UHUB_INCLUDES_H
|
||||||
|
#define HAVE_UHUB_INCLUDES_H
|
||||||
|
|
||||||
|
#define _FILE_OFFSET_BITS 64
|
||||||
|
|
||||||
|
#ifndef _GNU_SOURCE
|
||||||
|
# define _GNU_SOURCE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef WINSOCK
|
||||||
|
# include <winsock2.h>
|
||||||
|
# include <ws2tcpip.h>
|
||||||
|
#else
|
||||||
|
# include <sys/types.h>
|
||||||
|
# include <sys/time.h>
|
||||||
|
# include <arpa/inet.h>
|
||||||
|
# include <netdb.h>
|
||||||
|
# include <netinet/in.h>
|
||||||
|
# include <sys/ioctl.h>
|
||||||
|
# include <sys/socket.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
# include <assert.h>
|
||||||
|
# include <errno.h>
|
||||||
|
# include <fcntl.h>
|
||||||
|
|
||||||
|
#ifndef __sun__
|
||||||
|
# include <getopt.h>
|
||||||
|
# include <stdint.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#if !defined(WIN32)
|
||||||
|
# include <grp.h>
|
||||||
|
# include <pwd.h>
|
||||||
|
# include <sys/resource.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef SSL_SUPPORT
|
||||||
|
# include <openssl/ssl.h>
|
||||||
|
# include <openssl/err.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
|
# define USE_EPOLL
|
||||||
|
# include <sys/epoll.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef BSD_LIKE
|
||||||
|
# define USE_KQUEUE
|
||||||
|
# include <sys/event.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define USE_SELECT
|
||||||
|
# ifndef WINSOCK
|
||||||
|
# include <sys/select.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(WIN32)
|
||||||
|
# define HAVE_STRNDUP
|
||||||
|
# define HAVE_GETRLIMIT
|
||||||
|
# if !defined(__HAIKU__)
|
||||||
|
# define HAVE_MEMMEM
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(BSD_LIKE) || defined(__sun__)
|
||||||
|
# undef HAVE_STRNDUP
|
||||||
|
# undef HAVE_MEMMEM
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(WIN32)
|
||||||
|
/* Windows uses %Iu for size_t */
|
||||||
|
#define PRINTF_SIZE_T "%Iu"
|
||||||
|
#else
|
||||||
|
/* NOTE: does not work for old versions of gcc (like 2.95) */
|
||||||
|
#define PRINTF_SIZE_T "%zu"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define uhub_assert assert
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* HAVE_UHUB_INCLUDES_H */
|
||||||
@@ -138,23 +138,6 @@ ssize_t net_con_ssl_handshake(struct net_connection* con, enum net_con_ssl_mode
|
|||||||
#endif /* SSL_SUPPORT */
|
#endif /* SSL_SUPPORT */
|
||||||
|
|
||||||
|
|
||||||
int net_con_connect(struct net_connection* con, struct sockaddr* addr, size_t addr_len)
|
|
||||||
{
|
|
||||||
int ret = net_connect(con->sd, (struct sockaddr*) addr, addr_len);
|
|
||||||
if (ret == 0 || (ret == -1 && net_error() == EISCONN))
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else if (ret == -1 && (net_error() == EALREADY || net_error() == EINPROGRESS || net_error() == EWOULDBLOCK || net_error() == EINTR))
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ssize_t net_con_send(struct net_connection* con, const void* buf, size_t len)
|
ssize_t net_con_send(struct net_connection* con, const void* buf, size_t len)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
@@ -324,18 +307,15 @@ void net_con_callback(struct net_connection* con, int events)
|
|||||||
|
|
||||||
case tls_st_connected:
|
case tls_st_connected:
|
||||||
LOG_PROTO("tls_st_connected, events=%s%s, ssl_flags=%s%s", (events & NET_EVENT_READ ? "R" : ""), (events & NET_EVENT_WRITE ? "W" : ""), con->flags & NET_WANT_SSL_READ ? "R" : "", con->flags & NET_WANT_SSL_WRITE ? "W" : "");
|
LOG_PROTO("tls_st_connected, events=%s%s, ssl_flags=%s%s", (events & NET_EVENT_READ ? "R" : ""), (events & NET_EVENT_WRITE ? "W" : ""), con->flags & NET_WANT_SSL_READ ? "R" : "", con->flags & NET_WANT_SSL_WRITE ? "W" : "");
|
||||||
|
if (events & NET_EVENT_WRITE && con->flags & NET_WANT_SSL_READ)
|
||||||
// continue a SSL_read() that wants to write.
|
|
||||||
if (events & NET_EVENT_WRITE && con->flags & NET_WANT_SSL_WRITE)
|
|
||||||
{
|
{
|
||||||
con->callback(con, NET_EVENT_READ, con->ptr);
|
con->callback(con, events & NET_EVENT_READ, con->ptr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// continue a SSL_write() that wants to read something.
|
|
||||||
if (events & NET_EVENT_READ && con->flags & NET_WANT_SSL_WRITE)
|
if (events & NET_EVENT_READ && con->flags & NET_WANT_SSL_WRITE)
|
||||||
{
|
{
|
||||||
con->callback(con, NET_EVENT_WRITE, con->ptr);
|
con->callback(con, events & NET_EVENT_READ, con->ptr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -75,12 +75,6 @@ extern ssize_t net_con_recv(struct net_connection* con, void* buf, size_t len);
|
|||||||
*/
|
*/
|
||||||
extern ssize_t net_con_peek(struct net_connection* con, void* buf, size_t len);
|
extern ssize_t net_con_peek(struct net_connection* con, void* buf, size_t len);
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns 1 if connected, 0 if net_con_connect needs to be called again,
|
|
||||||
* and -1 if an error occured.
|
|
||||||
*/
|
|
||||||
extern int net_con_connect(struct net_connection* con, struct sockaddr* addr, size_t addr_len);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set timeout for connetion.
|
* Set timeout for connetion.
|
||||||
*
|
*
|
||||||
|
|||||||
182
src/system.h
182
src/system.h
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* uhub - A tiny ADC p2p connection hub
|
* uhub - A tiny ADC p2p connection hub
|
||||||
* Copyright (C) 2007-2009, Jan Vidar Krey
|
* Copyright (C) 2007-2010, Jan Vidar Krey
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -20,225 +20,127 @@
|
|||||||
#ifndef HAVE_UHUB_SYSTEM_H
|
#ifndef HAVE_UHUB_SYSTEM_H
|
||||||
#define HAVE_UHUB_SYSTEM_H
|
#define HAVE_UHUB_SYSTEM_H
|
||||||
|
|
||||||
#define _FILE_OFFSET_BITS 64
|
|
||||||
|
|
||||||
#if USE_REGPARM && __GNUC__ >= 3
|
|
||||||
#define REGPRM1 __attribute__((regparm(1)))
|
|
||||||
#define REGPRM2 __attribute__((regparm(2)))
|
|
||||||
#define REGPRM3 __attribute__((regparm(3)))
|
|
||||||
#else
|
|
||||||
#define REGPRM1
|
|
||||||
#define REGPRM2
|
|
||||||
#define REGPRM3
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef FORCEINLINE
|
|
||||||
#if __GNUC__ < 3
|
|
||||||
#define FORCEINLINE inline
|
|
||||||
#else
|
|
||||||
#define FORCEINLINE inline __attribute__((always_inline))
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef _GNU_SOURCE
|
|
||||||
#define _GNU_SOURCE
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__) || defined(__DragonFly__) || (defined(__APPLE__) && defined(__MACH__))
|
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__) || defined(__DragonFly__) || (defined(__APPLE__) && defined(__MACH__))
|
||||||
#define BSD_LIKE
|
# define BSD_LIKE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__CYGWIN__) || defined(__MINGW32__)
|
#if defined(__CYGWIN__) || defined(__MINGW32__)
|
||||||
#ifndef WINSOCK
|
# ifndef WINSOCK
|
||||||
#define WINSOCK
|
# define WINSOCK
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef WINSOCK
|
|
||||||
#include <winsock2.h>
|
|
||||||
#include <ws2tcpip.h>
|
|
||||||
#else
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <netdb.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
|
|
||||||
#ifndef __sun__
|
|
||||||
#include <getopt.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <signal.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#if !defined(WIN32)
|
|
||||||
#include <grp.h>
|
|
||||||
#include <pwd.h>
|
|
||||||
#include <sys/resource.h>
|
|
||||||
#define HAVE_STRNDUP
|
|
||||||
#ifndef __HAIKU__
|
|
||||||
#define HAVE_MEMMEM
|
|
||||||
#endif
|
|
||||||
#define HAVE_GETRLIMIT
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* printf and size_t support */
|
|
||||||
#if defined(WIN32)
|
|
||||||
/* Windows uses %Iu for size_t */
|
|
||||||
#define PRINTF_SIZE_T "%Iu"
|
|
||||||
#else
|
|
||||||
#define PRINTF_SIZE_T "%zu"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef SSL_SUPPORT
|
|
||||||
#include <openssl/ssl.h>
|
|
||||||
#include <openssl/err.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "../version.h"
|
|
||||||
|
|
||||||
#define uhub_assert assert
|
|
||||||
|
|
||||||
#ifdef __linux__
|
|
||||||
#define USE_EPOLL
|
|
||||||
#include <sys/epoll.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef BSD_LIKE
|
|
||||||
#define USE_KQUEUE
|
|
||||||
#include <sys/event.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define USE_SELECT
|
|
||||||
#ifndef WINSOCK
|
|
||||||
#include <sys/select.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(BSD_LIKE) || defined(__sun__)
|
|
||||||
#undef HAVE_STRNDUP
|
|
||||||
#undef HAVE_MEMMEM
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Detect operating system info.
|
* Detect operating system info.
|
||||||
* See: http://predef.sourceforge.net/
|
* See: http://predef.sourceforge.net/
|
||||||
*/
|
*/
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
#define OPSYS "Linux"
|
# define OPSYS "Linux"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_WIN32) || defined(__MINGW32__) || defined(_WIN64) || defined(__WIN32__) || defined(__WINDOWS__)
|
#if defined(_WIN32) || defined(__MINGW32__) || defined(_WIN64) || defined(__WIN32__) || defined(__WINDOWS__)
|
||||||
#define OPSYS "Windows"
|
# define OPSYS "Windows"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__APPLE__) && defined(__MACH__)
|
#if defined(__APPLE__) && defined(__MACH__)
|
||||||
#define OPSYS "MacOSX"
|
# define OPSYS "MacOSX"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__FreeBSD__)
|
#if defined(__FreeBSD__)
|
||||||
#define OPSYS "FreeBSD"
|
# define OPSYS "FreeBSD"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__OpenBSD__)
|
#if defined(__OpenBSD__)
|
||||||
#define OPSYS "OpenBSD"
|
# define OPSYS "OpenBSD"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__NetBSD__)
|
#if defined(__NetBSD__)
|
||||||
#define OPSYS "NetBSD"
|
# define OPSYS "NetBSD"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__sun__)
|
#if defined(__sun__)
|
||||||
#if defined(__SVR4) || defined(__svr4__)
|
# if defined(__SVR4) || defined(__svr4__)
|
||||||
#define OPSYS "Solaris"
|
# define OPSYS "Solaris"
|
||||||
#else
|
# else
|
||||||
#define OPSYS "SunOS"
|
# define OPSYS "SunOS"
|
||||||
#endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__HAIKU__)
|
#if defined(__HAIKU__)
|
||||||
#define OPSYS "Haiku"
|
# define OPSYS "Haiku"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Detect CPUs */
|
/* Detect CPUs */
|
||||||
#if defined(__alpha__) || defined(__alpha)
|
#if defined(__alpha__) || defined(__alpha)
|
||||||
#define CPUINFO "Alpha"
|
# define CPUINFO "Alpha"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__x86_64__) || defined(__x86_64) || defined(__amd64__) || defined(__amd64) || defined(_M_X64)
|
#if defined(__x86_64__) || defined(__x86_64) || defined(__amd64__) || defined(__amd64) || defined(_M_X64)
|
||||||
#define CPUINFO "AMD64"
|
# define CPUINFO "AMD64"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__arm__) || defined(__thumb__) || defined(_ARM) || defined(__TARGET_ARCH_ARM)
|
#if defined(__arm__) || defined(__thumb__) || defined(_ARM) || defined(__TARGET_ARCH_ARM)
|
||||||
#define CPUINFO "ARM"
|
# define CPUINFO "ARM"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__i386__) || defined(__i386) || defined(i386) || defined(_M_IX86) || defined(__X86__) || defined(_X86_) || defined(__I86__) || defined(__INTEL__) || defined(__THW_INTEL__)
|
#if defined(__i386__) || defined(__i386) || defined(i386) || defined(_M_IX86) || defined(__X86__) || defined(_X86_) || defined(__I86__) || defined(__INTEL__) || defined(__THW_INTEL__)
|
||||||
#define CPUINFO "i386"
|
# define CPUINFO "i386"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__ia64__) || defined(_IA64) || defined(__IA64__) || defined(__ia64) || defined(_M_IA64)
|
#if defined(__ia64__) || defined(_IA64) || defined(__IA64__) || defined(__ia64) || defined(_M_IA64)
|
||||||
#define CPUINFO "IA64"
|
# define CPUINFO "IA64"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__hppa__) || defined(__hppa)
|
#if defined(__hppa__) || defined(__hppa)
|
||||||
#define CPUINFO "PARISC"
|
# define CPUINFO "PARISC"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__m68k__) || defined(M68000)
|
#if defined(__m68k__) || defined(M68000)
|
||||||
#define CPUINFO "M68K"
|
# define CPUINFO "M68K"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__mips__) || defined(mips) || defined(__mips) || defined(__MIPS__)
|
#if defined(__mips__) || defined(mips) || defined(__mips) || defined(__MIPS__)
|
||||||
#define CPUINFO "MIPS"
|
# define CPUINFO "MIPS"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__POWERPC__) || defined(__ppc__) || defined(_ARCH_PPC) || defined(__powerpc) || defined(__powerpc__)
|
#if defined(__POWERPC__) || defined(__ppc__) || defined(_ARCH_PPC) || defined(__powerpc) || defined(__powerpc__)
|
||||||
#define CPUINFO "PowerPC"
|
# define CPUINFO "PowerPC"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__sparc__) || defined(__sparc)
|
#if defined(__sparc__) || defined(__sparc)
|
||||||
#define CPUINFO "SPARC"
|
# define CPUINFO "SPARC"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__sh__)
|
#if defined(__sh__)
|
||||||
#define CPUINFO "SuperH"
|
# define CPUINFO "SuperH"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* System includes */
|
||||||
|
#include "includes.h"
|
||||||
|
#include "../version.h"
|
||||||
|
|
||||||
|
|
||||||
/* Misc */
|
/* Misc */
|
||||||
#ifdef MSG_NOSIGNAL
|
#ifdef MSG_NOSIGNAL
|
||||||
#define UHUB_SEND_SIGNAL MSG_NOSIGNAL
|
# define UHUB_SEND_SIGNAL MSG_NOSIGNAL
|
||||||
#else
|
#else
|
||||||
#ifdef MSG_NOPIPE
|
# ifdef MSG_NOPIPE
|
||||||
#define UHUB_SEND_SIGNAL MSG_NOPIPE
|
# define UHUB_SEND_SIGNAL MSG_NOPIPE
|
||||||
#else
|
# else
|
||||||
#define UHUB_SEND_SIGNAL 0
|
# define UHUB_SEND_SIGNAL 0
|
||||||
#endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef INET6_ADDRSTRLEN
|
#ifndef INET6_ADDRSTRLEN
|
||||||
#define INET6_ADDRSTRLEN 46
|
# define INET6_ADDRSTRLEN 46
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef MIN
|
#ifndef MIN
|
||||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
# define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef MAX
|
#ifndef MAX
|
||||||
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
# define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* HAVE_UHUB_SYSTEM_H */
|
#endif /* HAVE_UHUB_SYSTEM_H */
|
||||||
|
|||||||
@@ -377,12 +377,12 @@ int ADC_client_connect(struct ADC_client* client, const char* address)
|
|||||||
client->callback(client, ADC_CLIENT_CONNECTING, 0);
|
client->callback(client, ADC_CLIENT_CONNECTING, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ret = net_con_connect(client->con, (struct sockaddr*) &client->addr, sizeof(struct sockaddr_in));
|
int ret = net_connect(net_con_get_sd(client->con), (struct sockaddr*) &client->addr, sizeof(struct sockaddr_in));
|
||||||
if (ret == 1)
|
if (ret == 0 || (ret == -1 && net_error() == EISCONN))
|
||||||
{
|
{
|
||||||
ADC_client_on_connected(client);
|
ADC_client_on_connected(client);
|
||||||
}
|
}
|
||||||
else if (ret == 0)
|
else if (ret == -1 && (net_error() == EALREADY || net_error() == EINPROGRESS || net_error() == EWOULDBLOCK || net_error() == EINTR))
|
||||||
{
|
{
|
||||||
if (client->state != ps_conn)
|
if (client->state != ps_conn)
|
||||||
{
|
{
|
||||||
@@ -400,17 +400,10 @@ int ADC_client_connect(struct ADC_client* client, const char* address)
|
|||||||
|
|
||||||
static void ADC_client_on_connected(struct ADC_client* client)
|
static void ADC_client_on_connected(struct ADC_client* client)
|
||||||
{
|
{
|
||||||
if (client->ssl)
|
|
||||||
{
|
|
||||||
net_con_ssl_handshake(client->con, net_con_ssl_mode_client, NULL);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
net_con_update(client->con, NET_EVENT_READ);
|
net_con_update(client->con, NET_EVENT_READ);
|
||||||
client->callback(client, ADC_CLIENT_CONNECTED, 0);
|
client->callback(client, ADC_CLIENT_CONNECTED, 0);
|
||||||
ADC_client_send(client, ADC_HANDSHAKE);
|
ADC_client_send(client, ADC_HANDSHAKE);
|
||||||
ADC_client_set_state(client, ps_protocol);
|
ADC_client_set_state(client, ps_protocol);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ADC_client_on_disconnected(struct ADC_client* client)
|
static void ADC_client_on_disconnected(struct ADC_client* client)
|
||||||
@@ -439,8 +432,8 @@ static int ADC_client_parse_address(struct ADC_client* client, const char* arg)
|
|||||||
{
|
{
|
||||||
char* split;
|
char* split;
|
||||||
int ssl = 0;
|
int ssl = 0;
|
||||||
struct hostent* dns = 0;
|
struct hostent* dns;
|
||||||
struct in_addr* addr = 0;
|
struct in_addr* addr;
|
||||||
|
|
||||||
if (!arg)
|
if (!arg)
|
||||||
return 0;
|
return 0;
|
||||||
@@ -452,11 +445,12 @@ static int ADC_client_parse_address(struct ADC_client* client, const char* arg)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* Check for ADC or ADCS */
|
/* Check for ADC or ADCS */
|
||||||
if (!strncmp(arg, "adc://", 6)) ssl = 0;
|
if (!strncmp(arg, "adc://", 6))
|
||||||
else if (!strncmp(arg, "adcs://", 7)) ssl = 1;
|
ssl = 0;
|
||||||
else return 0;
|
else if (!strncmp(arg, "adcs://", 7))
|
||||||
|
ssl = 1;
|
||||||
client->ssl = ssl;
|
else
|
||||||
|
return 0;
|
||||||
|
|
||||||
/* Split hostname and port (if possible) */
|
/* Split hostname and port (if possible) */
|
||||||
split = strrchr(client->hub_address + 6 + ssl, ':');
|
split = strrchr(client->hub_address + 6 + ssl, ':');
|
||||||
@@ -473,7 +467,9 @@ static int ADC_client_parse_address(struct ADC_client* client, const char* arg)
|
|||||||
/* Resolve IP address (FIXME: blocking call) */
|
/* Resolve IP address (FIXME: blocking call) */
|
||||||
dns = gethostbyname(client->hub_address + 6 + ssl);
|
dns = gethostbyname(client->hub_address + 6 + ssl);
|
||||||
if (dns)
|
if (dns)
|
||||||
|
{
|
||||||
addr = (struct in_addr*) dns->h_addr_list[0];
|
addr = (struct in_addr*) dns->h_addr_list[0];
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize the sockaddr struct.
|
// Initialize the sockaddr struct.
|
||||||
memset(&client->addr, 0, sizeof(client->addr));
|
memset(&client->addr, 0, sizeof(client->addr));
|
||||||
|
|||||||
@@ -105,7 +105,6 @@ struct ADC_client
|
|||||||
struct adc_message* info;
|
struct adc_message* info;
|
||||||
char recvbuf[ADC_BUFSIZE];
|
char recvbuf[ADC_BUFSIZE];
|
||||||
char sendbuf[ADC_BUFSIZE];
|
char sendbuf[ADC_BUFSIZE];
|
||||||
int ssl;
|
|
||||||
adc_client_cb callback;
|
adc_client_cb callback;
|
||||||
size_t s_offset;
|
size_t s_offset;
|
||||||
size_t r_offset;
|
size_t r_offset;
|
||||||
|
|||||||
@@ -82,8 +82,7 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
while (running)
|
while (running)
|
||||||
{
|
{
|
||||||
if (!net_backend_process())
|
net_backend_process();
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ADC_client_destroy(&client);
|
ADC_client_destroy(&client);
|
||||||
|
|||||||
Reference in New Issue
Block a user