From 25cc5d2c128b90a147b2b8c093b43b51158de2aa Mon Sep 17 00:00:00 2001 From: Saturneic Date: Thu, 17 Jan 2019 23:03:24 +0800 Subject: [PATCH] Fixed. --- addr.cpp | 4 ++++ client.cpp | 1 - clock.h | 2 +- cthread.h | 1 + net.h | 2 ++ server.h | 2 -- socket.cpp | 11 ++++++----- type.h | 3 ++- 8 files changed, 16 insertions(+), 10 deletions(-) diff --git a/addr.cpp b/addr.cpp index 28e9f32..f5d6432 100644 --- a/addr.cpp +++ b/addr.cpp @@ -42,6 +42,10 @@ socklen_t Addr::size(void){ return addr_size; } +void Addr::SetSize(void){ + addr_size = sizeof(address); +} + void Addr::SetPort(int port){ address.sin_port = htons(port); addr_size = sizeof(address); diff --git a/client.cpp b/client.cpp index 2283c2b..8c9b75a 100644 --- a/client.cpp +++ b/client.cpp @@ -12,7 +12,6 @@ int main(int argc, char *argv[]) { - try { Server client("127.0.0.1",9049,"127.0.0.1",9048); vector fargs = {1,0,0,1}; diff --git a/clock.h b/clock.h index c2079b3..525df0e 100644 --- a/clock.h +++ b/clock.h @@ -19,7 +19,7 @@ struct clock_register{ }; //初始化全局时钟 -void initClock(void) +void initClock(void); //设置全局线程时钟 void setThreadsClock(void); //时钟滴答调用函数 diff --git a/cthread.h b/cthread.h index 9b489d5..f277d7a 100644 --- a/cthread.h +++ b/cthread.h @@ -15,6 +15,7 @@ #include "server.h" class CThread; +class Server; //线程信息记录结构体 struct thread_args{ diff --git a/net.h b/net.h index c8b2ec3..677de0e 100644 --- a/net.h +++ b/net.h @@ -30,6 +30,8 @@ public: void SetPort(int port); // 重新设置IP地址管理结构所对应的IP地址 void SetIP(string ip_addr); +// IP地址管理结构的大小变量 + void SetSize(void); // 获得指向IP地址管理结构的指针 struct sockaddr *obj(void); }; diff --git a/server.h b/server.h index 214da68..b8924f3 100644 --- a/server.h +++ b/server.h @@ -109,6 +109,4 @@ void setServerClock(Server *psvr, int clicks); //服务器守护线程 void *serverDeamon(void *psvr); - - #endif /* server_h */ diff --git a/socket.cpp b/socket.cpp index 5963d7c..4e26382 100644 --- a/socket.cpp +++ b/socket.cpp @@ -10,14 +10,15 @@ Socket::Socket(string ip_addr, int port, bool server, bool tcp, bool ipv4){ + struct sockaddr_in &address = *(struct sockaddr_in *)addr.obj(); if(ipv4) - addr.address.sin_family = AF_INET; + address.sin_family = AF_INET; else - addr.address.sin_family = AF_INET6; - addr.address.sin_port = htons(port); + address.sin_family = AF_INET6; + address.sin_port = htons(port); this->port = port; - addr.address.sin_addr.s_addr = inet_addr(ip_addr.data()); - addr.setSize(); + address.sin_addr.s_addr = inet_addr(ip_addr.data()); + addr.SetSize(); this->server = server; this->tcp = tcp; this->ipv4 = ipv4; diff --git a/type.h b/type.h index c30d5b8..ff106d1 100644 --- a/type.h +++ b/type.h @@ -23,14 +23,15 @@ #include #include +#include #include #include #include #include -#include #include #include #include +#include using std::string; using std::vector;