⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clientmacro.h

📁 stun的一个客户端例子
💻 H
📖 第 1 页 / 共 2 页
字号:
/* Copyright (C) 2006 	Saikat Guha  and					
 *						Kuanyu Chou (xDreaming Tech. Co.,Ltd.)
 * All rights reserved.
 *
 * 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 2
 * 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, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/
#ifndef _CLIENT_MACRO_H_#define _CLIENT_MACRO_H_/***********************************************************************
*		 Win32 / Linux Intelx86 C++ Compiler File 		    		   				   
*--------------------------------------------------------------		   
*	[For]				{ XSTUNT Library }				  			   
*	[File name]     	{ ClientMacro.h }                          		   	   
*	[Description]
*	This file is the MACRO of main implementation code for XSTUNT library. 
*	About STUNT, please read: http://nutss.gforge.cis.cornell.edu/stunt.php for more references.
*	[History]
*  	2005.10		Saikat/Paul		Paper and experiment proposed
*	2006.03		Saikat/Kuanyu	C/C++ implementation code released 
***********************************************************************/
/************************************************************************************************************************/
/*			Macro Definition: Work for Client.cpp																							*/
/************************************************************************************************************************/
#ifdef _WIN32#define act_on_error(x, s, a)                                                               \    errno = 0;                                                                              \    if ((x) == -1) {                                                                        \		INT32 __act_errno;																	\	    char *__act_error;																	\		__act_errno = errno == 0 ? WSAGetLastError() : errno;								\		__act_error = strerror(__act_errno);												\        if (g_pDbgFile != NULL) fprintf(g_pDbgFile, "%s:%d: %s ... ERROR(%d)\n", "client.c", __LINE__, (s), __act_errno);	            \        if (__act_errno != 0) {                                                             \            if (g_pDbgFile != NULL) fprintf(g_pDbgFile, "%s:%d: ERROR(%d): %s\n", "client.c", __LINE__, __act_errno, __act_error);		\        }                                                                                   \        a;                                                                                  \    } else if (TEST_DEBUG) {                                                                 \        if (g_pDbgFile != NULL) fprintf(g_pDbgFile, "%s:%d: %s ... ok\n", "client.c", __LINE__, (s));					\    }                                                                                       \    do {                                                                                    \    } while(false)#else#define act_on_error(x, s, a)																\	if ((x) == -1) {                                                                        \        if (g_pDbgFile != NULL) fprintf(g_pDbgFile, "%s:%d: %s ... ERROR(%d)\n", "client.c", __LINE__, (s), errno);	            \        if (errno != 0) {                                                             \            if (g_pDbgFile != NULL) fprintf(g_pDbgFile, "%s:%d: ERROR(%d)\n", "client.c", __LINE__, errno);		\        }                                                                                   \        a;                                                                                  \    } else if (TEST_DEBUG) {                                                                 \        if (g_pDbgFile != NULL) fprintf(g_pDbgFile, "%s:%d: %s ... ok\n", "client.c", __LINE__, (s));					\    }                                                                                       \    do {                                                                                    \    } while(false)#endif#ifdef _WIN32#define log1(sock_logr, s, a1)                                                              \	do {                                                                                    \		struct timeb __log_buft;                                                            \		char __log_buf[2048];                                                               \		ftime(&__log_buft);                                                                 \		_snprintf(__log_buf, 2048, "%d.%03d:%s:%d:" s "\n", __log_buft.time, __log_buft.millitm, "client.c", __LINE__, (a1));	            \		write2((sock_logr), __log_buf, (INT32) strlen(__log_buf));			                                    \		if (TEST_DEBUG && g_pDbgFile != NULL) fprintf(g_pDbgFile, "LOGGED: %s", __log_buf);	\	} while(false)#else#define log1(sock_logr, s, a1)                                                              \	do {                                                                                    \		struct timeb __log_buft;                                                            \		char __log_buf[2048];                                                               \		ftime(&__log_buft);                                                                 \		snprintf(__log_buf, 2048, "%d.%03d:%s:%d:" s "\n", __log_buft.time, __log_buft.millitm, "client.c", __LINE__, (a1));	            \		write2((sock_logr), __log_buf, (INT32) strlen(__log_buf));			                                    \		if (TEST_DEBUG && g_pDbgFile != NULL) fprintf(g_pDbgFile, "LOGGED: %s", __log_buf);	\	} while(false)#endif#define readtimeout(s, socks, t, g)     \    do {                                \        Timeout.tv_sec = (t);           \        Timeout.tv_usec = 0;            \        FD_ZERO(&(socks));              \        FD_SET((s), &(socks));          \        if (select(1+(INT32)(s), &(socks), NULL, NULL, &Timeout) <= 0) goto g;    \    } while(false)#ifdef _WIN32#define log_on_error(x, s, g)   act_on_error((x), (s), log1(sock_logr, "%s ... ERROR", s); if (__act_errno != 0) {log1(sock_logr, "ERROR(%d)", __act_errno);} goto g)#else#define log_on_error(x, s, g)   act_on_error((x), (s), log1(sock_logr, "%s ... ERROR", s); if (errno != 0) {log1(sock_logr, "ERROR(%d)", errno);} goto g)#endif#define return_on_error(x, s)   act_on_error((x), (s), return)#define die_on_error(x, s)      act_on_error((x), (s), exit(1))#define cont_on_error(x, s)     act_on_error((x), (s), continue)#ifdef _WIN32#define write2(s,b,l)           send((s),((char *)b),l,0)#define read2(s,b,l)            recv((s),((char *)b),l,0)#define close2(s)               closesocket((s)); (s) = (SOCKET) -1; do { } while(0)#else#define write2(s,b,l)           write((s),((char *)b),l)#define read2(s,b,l)            read((s),((char *)b),l)#define close2(s)               close((s)); (s) = (SOCKET) -1; do { } while(0)#endif#define cont_on_write_error(sock, buf, size, s)     act_on_error((size) == write2((sock), (buf), (size)) ? 0 : -1, (s), close2((sock)); continue)#define cont_on_read_error(sock, buf, size, s)      act_on_error((size) == read2((sock), (buf), (size)) ? 0 : -1, (s), close2((sock)); continue)#ifdef _WIN32#define log_on_read_error(sock, buf, size, s, g)    act_on_error((size) == read2((sock), (buf), (size)) ? 0 : -1, (s), close2((sock)); log1(sock_logr, "%s ... ERROR", s); if (__act_errno != 0) {log1(sock_logr, "ERROR(%d)", __act_errno);} goto g)#else#define log_on_read_error(sock, buf, size, s, g)    act_on_error((size) == read2((sock), (buf), (size)) ? 0 : -1, (s), close2((sock)); log1(sock_logr, "%s ... ERROR", s); if (errno != 0) {log1(sock_logr, "ERROR(%d)", errno);} goto g)#endif#ifdef _WIN32#define log_on_write_error(sock, buf, size, s, g)   act_on_error((size) == write2((sock), (buf), (size)) ? 0 : -1, (s), close2((sock)); log1(sock_logr, "%s ... ERROR", s); if (__act_errno != 0) {log1(sock_logr, "ERROR(%d)", __act_errno);} goto g)#else#define log_on_write_error(sock, buf, size, s, g)   act_on_error((size) == write2((sock), (buf), (size)) ? 0 : -1, (s), close2((sock)); log1(sock_logr, "%s ... ERROR", s); if (errno != 0) {log1(sock_logr, "ERROR(%d)", errno);} goto g)#endif#define log_on_sendto_error(sock, buf, size, addr, addrlen, s, g)    act_on_error((size) == sendto((sock), (buf), (INT32)(size), 0, (addr), (addrlen)) ? 0 : -1, (s), close2((sock)); log1(sock_logr, "%s ... ERROR", s); goto g)
#define MAX(a, b)   ((a) > (b) ? (a) : (b))#define MIN(a, b)   ((a) < (b) ? (a) : (b))#ifdef _WIN32

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -