-
Notifications
You must be signed in to change notification settings - Fork 0
/
ipc_user.h
45 lines (37 loc) · 1013 Bytes
/
ipc_user.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
#ifndef __MY_IPC_USER_H__
#define __MY_IPC_USER_H__
#include "common.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h> // bool
#include <time.h>
#include <unistd.h> // close
#include <arpa/inet.h> // INET6_ADDRSTRLEN
#include <sys/sem.h> // semaphore
#include <sys/ipc.h> // semaphore
#define MAX_USERS 10
typedef struct node {
char name[BUF_SIZ];
int fd;
char IP[INET6_ADDRSTRLEN];
unsigned short port;
bool is_online;
char stMsg[BUF_SIZ];
char nowMsg[BUF_SIZ];
} Usernode;
typedef struct msgnode {
int fd;
Usernode *top;
int semid;
struct sembuf grab;
struct sembuf release;
} Msgnode;
int addUser(char *name, int fd, char *IP, unsigned short port, Usernode *top);
void broadcast(int fd, Usernode *top);
void unicast(int fd, char *to_name, char *msg, Usernode *top);
void unicast_Offline(int fd, Usernode *top);
void *unicast_Online(void *info);
void logoutUser(int fd, Usernode *top);
void showUser(Usernode *top);
#endif