易截截图软件、单文件、免安装、纯绿色、仅160KB

linux socket的select函数例子

使用select函数可以以非阻塞的方式和多个socket通信。程序只是演示select函数的使用,功能非常简单,即使某个连接关闭以后也不会修改当前连接数,连接数达到最大值后会终止程序。
1. 程序使用了一个数组fd_A,通信开始后把需要通信的多个socket描述符都放入此数组。
2. 首先生成一个叫sock_fd的socket描述符,用于监听端口。
3. 将sock_fd和数组fd_A中不为0的描述符放入select将检查的集合fdsr。
4. 处理fdsr中可以接收数据的连接。如果是sock_fd,表明有新连接加入,将新加入连接的socket描述符放置到fd_A。
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#define MYPORT 1234    // the port users will be connecting to
#define BACKLOG 5     // how many pending connections queue will hold
#define BUF_SIZE 200
int fd_A[BACKLOG];    // accepted connection fd
int conn_amount;    // current connection amount
void showclient()
{
    int i;
    printf("client amount: %d\n", conn_amount);
    for (i = 0; i < BACKLOG; i++) {
        printf("[%d]:%d  ", i, fd_A[i]);
    }
    printf("\n\n");
}
int main(void)
{
    int sock_fd, new_fd;  // listen on sock_fd, new connection on new_fd
    struct sockaddr_in server_addr;    // server address information
  


相关文档:

linux 进程线程时间片

 首先申明,我是菜鸟.菜到什么程度,大家看看下面的代码.
代码要求:取得1000次单独创建进程的时间.
[code:1:fdac913669]#include 
#include
#include
#include 
#include 
strut timeval {
long tv_sec; /* 秒数 */
long tv_usec; /* 微秒数  ......

深入理解linux内核笔记七:内存管理(1)之内存寻址

1 内存地址
       linux中,我们必须区分三种不同的地址
逻辑地址:机器语言指令中用来指定一个操作数和一个指令的地址.在X86中,每一个逻辑地址都由一个段(segment)和偏移量(offset)组成.
线性地址(也称虚拟地址):是一个32位无符号函数,可以表示高达4GB的地址,范围从0x00000000到0 ......

Linux性能测试工具(转)

Linux系统出现问题时,我们不仅需要查看系统日志信息,而且还要使用大量的性能监测工具来判断究竟是哪一部分(内存、CPU、硬盘……)出了问题。在Linux系统中,所有的运行参数保存在虚拟目录/proc中,换句话说,我们使用的性能监控工具取到的数据值实际上就是源自于这个目录,当涉及到系统高估时,我们就可以修 ......

Linux内核模块编程


摘要
Linux内核模块编程的资料有些纷繁复杂,有的过于简单,有的过于庞杂,我试图用笔记的形式想读者展示怎样来进程Linux模块编程,力图做到简明扼要,这篇文章也是作为本人备忘的资料,所以有些地方过于简略是难免的。本来这篇文章的目的就是让用户知其然,至于所以然还是请参考相应的资料,其实最好的资料莫过于Linux ......

Unix,Windows,Mac,Linux系统

 一 操作系统分类
http://www.csee.wvu.edu/~jdm/classes/cs258/OScat/
二 操作系统和时间线
http://en.wikipedia.org/wiki/Timeline_of_operating_systems
三 操作系统和公司
http://en.wikipedia.org/wiki/List_of_operating_systems
四 各种操作系统比较
http://en.wikipedia.org/wiki/Comparison_of_operat ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号