From 60a426c0742b3e7d8c5b557c7578df6eeeea377b Mon Sep 17 00:00:00 2001 From: brianluau Date: Wed, 5 Dec 2012 02:53:33 +0000 Subject: - Undid r16968: SVN Replaced with source:/trunk/src/@16966 (tid:74924). [16969:16991/trunk/src/] will be re-committed in the next 24 hours. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@16992 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/common/socket.h | 75 +++++++++++++++++++++++++++-------------------------- 1 file changed, 38 insertions(+), 37 deletions(-) (limited to 'src/common/socket.h') diff --git a/src/common/socket.h b/src/common/socket.h index 5c4008d62..7c0e02f5d 100644 --- a/src/common/socket.h +++ b/src/common/socket.h @@ -1,18 +1,18 @@ // Copyright (c) Athena Dev Teams - Licensed under GNU GPL // For more information, see LICENCE in the main folder -#ifndef _SOCKET_H_ +#ifndef _SOCKET_H_ #define _SOCKET_H_ #include "../common/cbasetypes.h" #ifdef WIN32 -#include "../common/winapi.h" -typedef long in_addr_t; + #include "../common/winapi.h" + typedef long in_addr_t; #else -#include -#include -#include + #include + #include + #include #endif #include @@ -38,15 +38,15 @@ typedef long in_addr_t; #define RFIFOREST(fd) (session[fd]->flag.eof ? 0 : session[fd]->rdata_size - session[fd]->rdata_pos) #define RFIFOFLUSH(fd) \ - do { \ - if(session[fd]->rdata_size == session[fd]->rdata_pos){ \ - session[fd]->rdata_size = session[fd]->rdata_pos = 0; \ - } else { \ - session[fd]->rdata_size -= session[fd]->rdata_pos; \ - memmove(session[fd]->rdata, session[fd]->rdata+session[fd]->rdata_pos, session[fd]->rdata_size); \ - session[fd]->rdata_pos = 0; \ - } \ - } while(0) + do { \ + if(session[fd]->rdata_size == session[fd]->rdata_pos){ \ + session[fd]->rdata_size = session[fd]->rdata_pos = 0; \ + } else { \ + session[fd]->rdata_size -= session[fd]->rdata_pos; \ + memmove(session[fd]->rdata, session[fd]->rdata+session[fd]->rdata_pos, session[fd]->rdata_size); \ + session[fd]->rdata_pos = 0; \ + } \ + } while(0) // buffer I/O macros #define RBUFP(p,pos) (((uint8*)(p)) + (pos)) @@ -71,32 +71,33 @@ typedef int (*RecvFunc)(int fd); typedef int (*SendFunc)(int fd); typedef int (*ParseFunc)(int fd); -struct socket_data { - struct { - unsigned char eof : 1; - unsigned char server : 1; - unsigned char ping : 2; - } flag; +struct socket_data +{ + struct { + unsigned char eof : 1; + unsigned char server : 1; + unsigned char ping : 2; + } flag; - uint32 client_addr; // remote client address + uint32 client_addr; // remote client address - uint8 *rdata, *wdata; - size_t max_rdata, max_wdata; - size_t rdata_size, wdata_size; - size_t rdata_pos; - time_t rdata_tick; // time of last recv (for detecting timeouts); zero when timeout is disabled + uint8 *rdata, *wdata; + size_t max_rdata, max_wdata; + size_t rdata_size, wdata_size; + size_t rdata_pos; + time_t rdata_tick; // time of last recv (for detecting timeouts); zero when timeout is disabled - RecvFunc func_recv; - SendFunc func_send; - ParseFunc func_parse; + RecvFunc func_recv; + SendFunc func_send; + ParseFunc func_parse; - void *session_data; // stores application-specific data related to the session + void* session_data; // stores application-specific data related to the session }; // Data prototype declaration -extern struct socket_data *session[FD_SETSIZE]; +extern struct socket_data* session[FD_SETSIZE]; extern int fd_max; @@ -130,21 +131,21 @@ extern void set_nonblocking(int fd, unsigned long yes); void set_defaultparse(ParseFunc defaultparse); // hostname/ip conversion functions -uint32 host2ip(const char *hostname); -const char *ip2str(uint32 ip, char ip_str[16]); -uint32 str2ip(const char *ip_str); +uint32 host2ip(const char* hostname); +const char* ip2str(uint32 ip, char ip_str[16]); +uint32 str2ip(const char* ip_str); #define CONVIP(ip) ((ip)>>24)&0xFF,((ip)>>16)&0xFF,((ip)>>8)&0xFF,((ip)>>0)&0xFF #define MAKEIP(a,b,c,d) (uint32)( ( ( (a)&0xFF ) << 24 ) | ( ( (b)&0xFF ) << 16 ) | ( ( (c)&0xFF ) << 8 ) | ( ( (d)&0xFF ) << 0 ) ) uint16 ntows(uint16 netshort); -int socket_getips(uint32 *ips, int max); +int socket_getips(uint32* ips, int max); extern uint32 addr_[16]; // ip addresses of local host (host byte order) extern int naddr_; // # of ip addresses void set_eof(int fd); -/// Use a shortlist of sockets instead of iterating all sessions for sockets +/// Use a shortlist of sockets instead of iterating all sessions for sockets /// that have data to send or need eof handling. /// Adapted to use a static array instead of a linked list. /// -- cgit v1.2.3-60-g2f50