设为首页 加入收藏

TOP

Linux上的一个简单的多人聊天室(二)
2014-11-24 08:39:37 来源: 作者: 【 】 浏览:2
Tags:Linux 一个 简单 多人 聊天室
e_now));
}
int i_lseek(int fd, off_t size, int position)
{
if (-1 == lseek(fd, size, position))
{
perror("seek error");
exit(1);
}
return(0);
}
int i_saveto_chat(struct msg *pmsg)
{
struct chat_history hstr;



bzero(&hstr, HSTR_LEN);
count = count + 1;
hstr.count =count;
hstr.from = pmsg->id_from;
hstr.to = pmsg->id_to;
strncpy(hstr.content, pmsg->content, CNTNT_LEN);
strncpy(hstr.time, i_get_time(), 25);


i_lseek(mainfd, 0, SEEK_END);


i_write(mainfd, &hstr, HSTR_LEN);


return(0);
}


int i_print_history(int len, int i)
{
struct chat_history chat_reader;
int j;
int position;

bzero(&chat_reader, HSTR_LEN);
if (i != 0)
{
position = len*i*HSTR_LEN;
i_lseek(mainfd, position, SEEK_END);
}
else
{
position = len*i*HSTR_LEN;


i_lseek(mainfd, HSTR_LEN, SEEK_SET);
}

for (j = 1; j <= len; j++)
{

i_read(mainfd, &chat_reader, HSTR_LEN);
printf("\n#item%d:id%dto id%d \n", j,
chat_reader.from, chat_reader.to);
i_print(chat_reader.content, CNTNT_LEN);
printf("\n Time:%s\n", chat_reader.time);
}


return(0);
}


#endif


首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Linux下SPI从设备驱动的编写 下一篇Android 开发人员必须掌握的 10 ..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·有没有哪些高效的c++ (2025-12-27 08:20:57)
·Socket 编程时 Accep (2025-12-27 08:20:54)
·计算机网络知识点总 (2025-12-27 08:20:52)
·一篇说人话的文章, (2025-12-27 07:50:09)
·Python Web框架哪家 (2025-12-27 07:50:06)