基于Linux的消息队列及多线程编程实现的聊天室(二)代码分析

先将代码贴出来,然后慢慢再解释.

@Makefile

 

OBJS := server client
all: $(OBJS)

server: msg_svr.c msg.h 
	gcc -o $@ $^ -D_DEBUG

client: msg_client.c msg.h
	gcc -o $@ $^ -lpthread

clean:
	$(RM) $(OBJS)

 

 

 

@msg.h

 

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#define   MSG_FILE "/tmp/msg_server"    
#define   BUFFER 255    
#define   PERM S_IRUSR | S_IWUSR    

#define 	OK			1 
#define 	ERR			0

// msg type
#define   TYPE_SERVER		1000
#define   TYPE_SERVER_STR	"1000"

// msg target string
#define   SERVER_STR		"SERVER"
#define   TO_ALL_STR		"ALL"

// send cmd
// L, I, O is send to server
#define 	CMD_LIST		'L'
#define 	CMD_LOGIN		'I'
#define 	CMD_LOGOUT		'O'
#define 	CMD_TOA

你可能感兴趣的:(其它杂项)