📄 serversock.h
字号:
/**********************************************************************************************
* Copyright (c) 1994,合肥合能电气有限责任公司
* All rights reserved.
*
* 文件名称: serversock.h
* 文件标识:
* 摘要: socket服务器端
*
* 当前版本: 1.0
* 作者: Highmayor
* 完成日期: 2005年7月18日
*
* 取代版本: 1.0
* 原作者: Highmayor
* 完成日期: 2005年7月18日
***********************************************************************************************/
#ifndef _SERVERSOCK_H_
#define _SERVERSOCK_H_
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <assert.h>
#include "evardef.h"
#include "mytype.h"
#if defined (WIN32)
#include <winsock2.h>
#elif defined (LINUX)
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <netinet/in.h>
#include <errno.h>
#include <unistd.h>
#include <time.h>
#include <sys/time.h>
#include <error.h>
#include <netdb.h>
#include "sockdef.h"
#endif
//detailed information of every client
typedef struct ClientOnline
{
char ClientIP[16];//IP of client, the ClientIP[15] must be set to '\0'
//int ClientPort; //port of client,default is 1024 in current version
int ClientSock; //socket no. of client
} ClientOnline;
//manage all sockets,include the daemon socket
//use struct SocketsMsg to save the information of readfds,writefds,exceptfds
typedef struct ServerSockets
{
int DaemonSock; //the socket to listen
int DaemonPort; //the port to listen
int RequestNum; //the number of client socket which is waitting for connecting
int clientcount; //count of all onlined client socket
ClientOnline clientonline[64]; //client information
fd_set readfds, writefds, exceptfds; //set of every client socket's attribute
int ReadNum; //the number of client socket that can be read
int ReadQueue[64]; //the sn. of client socket that can be read in the array clientonline[64]
int WriteNum; //the number of client socket that can be write
int WriteQueue[64]; //the sn. of client socket that can be write in the array clientonline[64]
int ExceptNum; //the number of client socket that be exception
int ExceptQueue[64]; //the sn. of client socket that be exception the array clientonline[64]
} ServerSockets;
void InitServerSocks(ServerSockets *ssockets);
MYBOOL mylisten(SOCKET s, int backlog);
int InitSocketsStruct(char * servicename, char * protocol, ServerSockets *ssockets);
int InitPassiveSock(char * servicename, char * protocol, ServerSockets *ssockets);
void CloseMainSock(ServerSockets *ssockets);
int CreateConnection(struct in_addr *sin_addr, ServerSockets *ssocket);
int MyAccept(ServerSockets *ssocket);
MYBOOL CloseConnection(int Sockno, ServerSockets *ssocket);
int QuerySockets(ServerSockets *ssocket);
int SendPacket(int Sockno, void *buf, int len, ServerSockets *ssocket);
int RecvPacket(int Sockno, void *buf, int size, ServerSockets *ssocket);
void FilterDoubleClient(ServerSockets *ssocket, struct sockaddr_in * doubleaddr);
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -