中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當前位置: 首頁 > news >正文

企業(yè)營銷網(wǎng)站開發(fā)建設(shè)專家山東濰坊疫情最新消息

企業(yè)營銷網(wǎng)站開發(fā)建設(shè)專家,山東濰坊疫情最新消息,北京網(wǎng)站優(yōu)化軟件公司,萬能應(yīng)用商店下載常用函數(shù) //創(chuàng)建/獲取消息隊列 int msgget (key_t key, int msgflg); /* key : 為鍵值,ftok(); msgflg:IPC_CREAT - 創(chuàng)建,不存在即創(chuàng)建,已存在即獲取,除非… IPC_EXCL - 排斥,已存在即失敗。 */// 向消息隊列發(fā)送消息 int msgs…

常用函數(shù)

//創(chuàng)建/獲取消息隊列 
int msgget (key_t key, int msgflg);
/*
key : 為鍵值,ftok();
msgflg:IPC_CREAT - 創(chuàng)建,不存在即創(chuàng)建,已存在即獲取,除非… IPC_EXCL - 排斥,已存在即失敗。
*/// 向消息隊列發(fā)送消息 
int msgsnd (int msqid, const void* msgp,size_t msgsz, int msgflg);
/*
msqid : msgget()返回
msgp : 包含消息類型和消息數(shù)據(jù)的內(nèi)存塊.前4個字節(jié)必須是一個大于0的整數(shù),代表消息類型,其后消息數(shù)據(jù)
msgsz:不包括消息類型的,只算消息數(shù)據(jù)的內(nèi)存大小
msgflg :IPC_NOWAIT內(nèi)核中的消息隊列緩沖區(qū)沒有足夠的空閑空間時,此函數(shù)不會阻塞,而是返回-1
*///從消息隊列接收消息
ssize_t msgrcv (int msqid, void* msgp, size_t msgsz,long msgtyp, int msgflg);
/*
msqid : msgget()返回
msgp : 包含消息類型和消息數(shù)據(jù)的內(nèi)存塊
smgsz:接收的內(nèi)存大小,如果接收到的內(nèi)存>smgsz,則只會截取內(nèi)存大小部分
msgtyp:=0 - 返回消息隊列中的第一條消息。 >0 - 若msgflg參數(shù)不包含MSG_EXCEPT位,則返回消息隊列中第一個類型為msgtyp的消息,若msgflg參數(shù)包含MSG_EXCEPT位,則返回消息隊列中第一個類型不為msgtyp的消息。 <0 - 返回消息隊列中類型小于等于msgtyp的絕對值的消息,若有多個,則取類型最小者。
*///銷毀/控制消息隊列 
int msgctl (int msqid, int cmd, struct msqid_ds* buf); 
/*
IPC_STAT 
獲取消息隊列的屬性
IPC_SET 
設(shè)置消息隊列的屬性
IPC_RMID - 立即刪除消息隊列。 此時所有阻塞在對該消息隊列的,msgsnd和msgrcv函數(shù)調(diào)用,都會立即返回失敗,errno為EIDRM。*/

例子

為了展示例程,部分代碼刪減,且多個文件合并了,開發(fā)過程中,請不要模仿,這樣不規(guī)范。

server

#include "server.h"
#include "server_function.h"
#include "fileoper.h"
#include "slinklist.h"
#include <stdbool.h>
#include <signal.h>
#include <assert.h>
#include "client.h"/*typedef struct Msg{int type;char msg[1024];
}Msg;typedef struct Back{int type;char msg[1024];
}Back;*/
#define PATH "/home/zhizhen/項目/本地銀行"
#define SERVER 100
#define CLIENT 101int id1 ,id2;
Slink list = NULL;
Slink node = NULL;
void myexit(int sig){file_write(list);slink_destory(list);des_msg(id1);des_msg(id2);printf("退出成功\n");exit(0);
}
int server_run(){list = slink_create();assert(list != NULL);file_read(list);int id1 = create_msg(PATH,SERVER);int id2 = create_msg(PATH,CLIENT);assert(id1 != -1 && id2 != -1);while(1){	signal(SIGINT,myexit);Msg msg = {};//后面定義的,接收的消息的結(jié)構(gòu)體Back back = {};int ret = 0;size_t msgsz = 0;//接收消息ssize_t sz = recv_msg(id1,(void *)&msg,sizeof(msg.msg));assert(sz != -1);if(sz == 0){printf("該用戶退出了\n");	node = NULL;}int opt = msg.type;switch(opt){case R:msgsz = recv_Reg(&msg,&back,list);break;case E:node = recv_Ent(&msg,&back,list);msgsz = sizeof(B_Ent);break;case G:msgsz = recv_GetM(&msg,&back,list,node);break;case S:msgsz = recv_SaveM(&msg,&back,list,node);break;case T:msgsz = recv_TranM(&msg,&back,list,node);break;case C:msgsz = recv_ChgP(&msg,&back,list,node);break;case D:msgsz = recv_Des(&msg,&back,list,node);break;}Slink next1 = list->next;int i = 1;while(next1 != NULL){Client *p = (Client *)(next1->elem);printf("-------------------\n");printf("*******%d*******\n",i);i++;printf("id:%s\n",p->id);printf("name:%s\n",p->name);printf("password:%s\n",p->password);printf("tel:%s\n",p->tel);printf("money:%d\n",p->money);printf("------------------\n");next1 = next1->next;}ret = send_msg(id2,(const void *)&back,msgsz);//發(fā)送反饋assert(ret != -1);}
}

client

#include "client.h"
#include <stdbool.h>
#include <assert.h>static void menu(){printf("--------%d.注冊\n",R);printf("--------%d.登錄\n",E);printf("--------非%d和%d即:退出\n",R,E);printf(">>>>\n");
}static void menu_Ent(){printf("******%d.取錢\n",G);printf("******%d.充值\n",S);printf("******%d.轉(zhuǎn)賬\n",T);printf("******%d.修改密碼\n",C);printf("******%d.銷戶\n",D);printf("*******0.退出\n");printf(">>>>>\n");
}/*typedef struct Msg{int type;char msg[1024];
}Msg;typedef struct Back{int type;char msg[1024];
}Back;*/int create_msg(char *s,int id){key_t key = ftok(s,id);assert(key != -1);return msgget(key,IPC_CREAT|0644);
}
int send_msg(int msqid,const void *msg,size_t msgsz){return msgsnd(msqid,msg,msgsz,0);
}
int recv_msg(int msqid,void *msg,size_t msgsz){return msgrcv(msqid,msg,msgsz,0,0);
}
int des_msg(int msqid){return msgctl(msqid,IPC_RMID,NULL);
}
int client_run(){int id1 = create_msg(PATH,SERVER);int id2 = create_msg(PATH,CLIENT);assert(id1 != -1 && id2 != -1);
Beg:while(1){Msg msg = {};size_t msgsz = 0;Back back = {};int ret = 0;menu();int opt = 0;scanf("%d",&opt);switch(opt){case R:msgsz = send_Reg(&msg);break;case E:msgsz = send_Ent(&msg);break;default:printf("退出成功\n");exit(0);break;}ret = send_msg(id1,(const void *)&msg,msgsz);assert(ret != -1);ret = recv_msg(id2,(void *)&back,sizeof(back.msg));assert(ret != -1);opt = back.type;switch(opt){case R:back_Reg(&back);break;case E:{if(back_Ent(&back) == 1){while(1){menu_Ent();int opt = 0;Msg msg = {};Back back = {};size_t msgsz = 0;scanf("%d",&opt);switch(opt){case G:msgsz = send_GetM(&msg);break;case S:msgsz = send_SaveM(&msg);break;case T:msgsz = send_TranM(&msg);break;case C:msgsz = send_ChgP(&msg);break;case D:msgsz = send_Des(&msg);break;default:goto Beg;printf("退出成功!\n");break;}ret = send_msg(id1,(const void *)&msg,msgsz);assert(ret != -1);ret = recv_msg(id2,&back,sizeof(back.msg));assert(ret != -1);opt = back.type;switch(opt){case G:back_GetM(&back);break;case S:back_SaveM(&back);break;case T:back_TranM(&back);break;case C:back_ChgP(&back);break;case D:back_Des(&back);break;}}}else{printf("登錄失敗!\n");}break;}}}
}
http://www.risenshineclean.com/news/55242.html

相關(guān)文章:

  • wordpress圖片無法顯示百度seo新算法
  • 鄭州網(wǎng)站制作推廣站長seo
  • 如何做網(wǎng)站結(jié)構(gòu)優(yōu)化微信推廣廣告在哪里做
  • 全flash網(wǎng)站欣賞百度搜索引擎優(yōu)化指南最新版
  • 做網(wǎng)站需要買什么電商平臺開發(fā)需要多少錢
  • 企業(yè)網(wǎng)站seo搜索引擎關(guān)鍵詞優(yōu)化技巧
  • 網(wǎng)站改名 備案佛山網(wǎng)站建設(shè)方案服務(wù)
  • 定制級高端網(wǎng)站建設(shè)seo搜索引擎實訓(xùn)心得體會
  • b站24小時免費直播下載迅雷bt磁力鏈 最好用的搜索引擎
  • 企業(yè)網(wǎng)站優(yōu)化方法包括sem推廣計劃
  • 呂梁做網(wǎng)站互聯(lián)網(wǎng)公司排名100強
  • 沈陽品牌網(wǎng)站建設(shè)推廣方案設(shè)計
  • 常州seo網(wǎng)絡(luò)推廣seo優(yōu)化大公司排名
  • 網(wǎng)站設(shè)計怎么收費免費企業(yè)網(wǎng)站模板源碼
  • 北京市保障房建設(shè)官方網(wǎng)站能讓網(wǎng)絡(luò)非常流暢的軟件
  • 人們做網(wǎng)站怎么賺錢seo系統(tǒng)優(yōu)化
  • 華為外包做的網(wǎng)站數(shù)據(jù)分析師一般一個月多少錢
  • 小語種網(wǎng)站建設(shè)關(guān)鍵詞分類
  • 凡科網(wǎng)站建設(shè)套餐報價汨羅網(wǎng)站seo
  • 鞏義做網(wǎng)站推廣淺談一下網(wǎng)絡(luò)營銷的幾個誤區(qū)
  • wordpress防黑網(wǎng)站優(yōu)化seo
  • 百度做網(wǎng)站教程武漢排名seo公司
  • 網(wǎng)站彈窗特效注冊google賬號
  • 個人直播網(wǎng)站開發(fā)自己怎么做網(wǎng)址開網(wǎng)站
  • 淘寶 網(wǎng)站開發(fā) 退貨seo建站
  • 網(wǎng)絡(luò)工程就業(yè)方向及就業(yè)前景百度推廣賬戶優(yōu)化
  • 網(wǎng)站建設(shè)的主要功能谷歌在線瀏覽入口
  • 云服務(wù)器ecs建網(wǎng)站it培訓(xùn)機構(gòu)哪家好
  • 網(wǎng)站建設(shè)情況簡介seo全網(wǎng)營銷公司
  • 建德網(wǎng)站seo溫州seo結(jié)算