📄 session.h
字号:
#ifndef _SESSION_H_#define _SESSION_H_
#include<iostream>
using namespace std;
class Session{
friend class SessionList;
typedef struct User
{
char UserName[16];
char UserId[16];
int Sockfd;
struct User *next;
} User ;
User *head;
int Count;
int SessionId;
public:
/*Session(int id,char *list,int c)
{
head=new User;
head->next=NULL;
Count=c;
SessionId=id;
User *p=NULL;
int i;
char id[16]={'\0'};
for(i=0;i<c;i++)
{
p=new User;
strcpy(p->UserName,list+i*31);
memcpy(id,list+i*31+15,15);
id[15]='\0';
sprintf(p->UserId,"%d",atoi(id);
p->next=head->next;
head->next=p;
}
}*/
Session(int id)
{
head = new User;
head->next = NULL;
Count = 0;
SessionId = id;
}
~Session()
{
User *p=head->next;
while(head)
{
delete head;
head=p;
if(p!=NULL)
p=p->next;
}
}
int getCount(){return Count;}
int getSessionId(){return SessionId;}
bool addUser( int id,char *name,int Sockfd);
bool deleteUser(int id);
bool deleteid(int socketid);
void getSockfd(int *sockfd);
// getsockfd 函数有两个默认参数。
char* getUser();
};
#endif
class SessionList{
Session *Slist;
SessionList *next;
public:
SessionList() {Slist= NULL; next=NULL;}
~SessionList(){ if(NULL!=Slist)delete Slist;if(NULL!=next) delete next;}
Session * findSession(int id);
bool addSession(Session *session);
bool deleteSession(int id);
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -