-
Notifications
You must be signed in to change notification settings - Fork 0
/
Socket.h
63 lines (52 loc) · 1.22 KB
/
Socket.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#pragma once
#ifndef MYSOCKET
#define MYSOCKET
#include "stdafx.h"
#include "Header.h"
#include "ChatManager.h"
class chatManager;
struct Buffer{
char data[PACKETSIZE]="\0";
int slen = 0, rlen = 0;
};
class Socket {
public:
Socket() ;
Event getMyStatus();
void setMyStatus(int m);
void setMyID(int &id);
int getMyID()const;
void setFD(SOCKET &fd);
SOCKET getFD()const;
void setCP(HANDLE cp);
void AssingCP();
void onRead();
void setRecvEvent();
void Send_(Packet&);
void setSendEvent();
void Disconnect();
void setChatManager(chatManager* mngr);
chatManager* getChatMngr();
Buffer* getsndBuffer() { return &sendpkt; }
Buffer* getrcvBuffer() { return &recvpkt; }
char* getMyNick() { return myNick; }
void setMyNick(char *nick,int len) {
memcpy(myNick, nick, len);
}
void setMyAddr(struct sockaddr_in &tad) {
memcpy(&myAddres, &tad, sizeof(myAddres));
}
struct sockaddr_in getMyAddr()const { return myAddres; }
private:
int myID;
SOCKET m_fd;
HANDLE m_cp;
OverlappedStruct m_readevent, m_sendevent;
Event myStatus;
struct sockaddr_in myAddres;
Buffer recvpkt, sendpkt;
chatManager *cmngr;
std::mutex mMutex;
char myNick[10] = "\0";
};
#endif