⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 communication.c.svn-base

📁 可以作为Linux教学用的程序
💻 SVN-BASE
字号:
/* communication.c */#include <sys/types.h>#include <sys/ipc.h>#include <sys/msg.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <netinet/in.h>#include <arpa/inet.h>#include <unistd.h>#include "communication.h"static long id;static int c2s_id;static int s2c_id;int communication_init(){	id = (long)getpid();		if ((c2s_id = 		msgget(C2S_KEY, PERM | IPC_CREAT)) < 0) {		perror("MSG Key");		exit(-1);	}	if ((s2c_id = 		msgget(S2C_KEY, PERM | IPC_CREAT)) < 0) {		perror("MSG Key");		exit(-1);	}	return 0;}int send_msg(const char *msg){	int len;	msg_data_t data_send;	strcpy(data_send.text, msg);	data_send.type = id;	len = strlen(msg);        	msgsnd(c2s_id, &data_send, len + 1, 0);	return 0;}int recv_msg(char * buf, int max){	msg_data_t data_recv;	if (msgrcv(s2c_id, (void *)&data_recv, MAX_MSG_LEN, id , 0) == -1) {		perror("msgrcv failed with error");		exit(-1);	}	strcpy(buf, data_recv.text);	return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -