摘要: 1.read系统调用测试程序:客户端向服务器端(tcp)发送一个”hello”字符串,服务器端读取并echo到客户端。服务器端主要代码:char buf[4096];int r = tcp_readn(sock, buf, 4096);int w = tcp_writen(sock, buf, r);客户端主要代码:char buf[4096];int w = tcp_writen(sock, “hello”, 5);int r = tcp_readn(sock, buf, 4096);问题描述:客户端write调用成功,服务器端阻塞在tcp_readn上,tcp_readn的实现如下所示:i 阅读全文
posted @ 2012-01-10 18:43 vivianC 阅读(323) 评论(0) 推荐(0)
摘要: /** 使用信号实现父子进程之间的同步** TELL_WAIT(): set things up for TELL_xxx & WAIT_xxx* TELL_PARENT(): tell parent we are done* WAIT_PARENT(): wait for parent* TELL_CHILD(): tell child we are done* WAIT_CHILD(): wait for child** SIGUSR1: the signal parent sends to child* SIGUSR2: the signal child sends to par 阅读全文
posted @ 2012-01-10 18:41 vivianC 阅读(1305) 评论(0) 推荐(0)
摘要: 线程的创建int pthread_create(pthread_t *tid, const pthread_attr_t *attr,void *(*start_rtn)(void), void *arg);pthread_create创建成功时返回0,tid存放创建线程的id,第二个参数为创建线程的属性,第三个为线程的执行路径,第四个参数为传给创建线程的参数线程的退出线程可以选择三种方式退出,在不终止整个进程的情况下停止它的执行流。1.线程从启动例程中返回,返回值是线程的退出码。2.线程被同一进程中的其它线程取消。3.线程调用pthread_exit();4.主进程结束,该进程中的所有线程也 阅读全文
posted @ 2012-01-10 18:39 vivianC 阅读(1194) 评论(0) 推荐(0)
摘要: hash函数主要用于将“大范围”映射到“小范围”,如MD5将任意长度的数据计算出128bit的签名值,RSHash等函数将任意长度的数据转换成32bit的无符号整型,好的hash函数拥有高性能以及低hash冲突。hash函数主要通过加减乘除及移位等操作来计算最终结果,hash函数的分类参考:http://nicoleamanda.blog.163.com/blog/static/7499610720091013233598/【1】http://yuhuafx.blog.hexun.com/58369610_d.html【2】【1】【2】中的hash函数用于将数据序列计算出32bit的hash值 阅读全文
posted @ 2012-01-10 18:29 vivianC 阅读(262) 评论(0) 推荐(0)