zoukankan      html  css  js  c++  java
  • 网络编程之select

    网络编程学习模式,有select、poll、epoll等方式,测试使用三种方式来测试网络连接。

    /*


    */


    #ifndef _CCNET_H
    #define _CCNET_H

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <assert.h>
    #include <unistd.h>
    #include <assert.h>
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <netinet/tcp.h>
    #include <netdb.h>
    #include <netinet/in.h>
    #include <arpa/inet.h>


    //@file
    //@brief 网络处理函数封装

    /**
    * @brief 带超时(微秒级)的tcp连接函数
    * @param host : 连接主机名,不能为NULL
    * @param port : 连接主机监听端口
    * @param timeout : 最大超时时间(微妙)的指针,不能为NULL,连接成功timeout将被设置为剩余的时间
    * @param name : 连接模块名
    * @return -1 连接失败或超时
    * @return socket 连接成功的socket
    */
    int CCConnectO(const char *host, int port, int *timeout, const char *name);

    /**
    * @brief 带超时(微秒级)的socket读操作
    * @param sock : 已连接的socket
    * @param buf : 读入的空间
    * @param len : 读入的最大长度
    * @param timeout : 最大超时时间(微妙)的指针,不能为NULL,函数返回后timeout将被设置为剩余的时间
    * @param name : 连接模块名
    * @return -1 读失败
    * @return 实际读到的字符数
    */
    int CCReadO(int sock, void *buf, ssize_t len, int *timeout, const char *name);

    /**
    * @brief 带超时(微秒级)的socket读操作,直到读到的内容中出现了stop串,或者读到len长度,或超时。
    * @param sock : 已连接的socket
    * @param buf : 读入的空间
    * @param len : 读入的最大长度
    * @param timeout : 最大超时时间(微妙)的指针,不能为NULL,函数返回后timeout将被设置为剩余的时间
    * @param name : 连接模块名
    * @param stop : 当读到内容中出现stop字串时,停止读
    * @return -1 读失败
    * @return 实际读到的字符数
    */
    int CCReadOS(int sock, void *buf, ssize_t len, int *timeout, const char *name,
    const char *stop);

    /**
    * @brief 带超时(微秒级)的socket写操作
    * @param sock : 已连接的socket
    * @param buf : 要写出的空间
    * @param len : 要写出的最大长度
    * @param timeout : 最大超时时间(微妙)的指针,不能为NULL,函数返回后timeout将被设置为剩余的时间
    * @param name : 连接模块名
    * @return -1 读失败
    * @return 实际写出的字符数
    */
    int CCWriteO(int sock, void *buf, ssize_t len, int *timeout,
    const char *name);

    /**
    * @brief 关闭socket
    * @param fd : 已连接的socket
    * @return -1 关闭失败
    * @return 0 成功关闭
    */
    int CCClose(int fd);

    /**
    * @brief 开启tcp监听端口
    * @param port : 端口
    * @param queue : listen等待队列长度
    * @return -1 失败
    * @return 成功返回开启监听的fd
    */
    int CCTcpListen(const char *host, int port, int queue);

    #endif // _CCNET_H
    /* vim: create noet: */

  • 相关阅读:
    WebClient与WebRequest差异
    自定义控件的构建(4)
    自定义控件的构建(6)
    Sliverlight中PagedCollectionView的总结
    自定义控件的构建(13)
    自定义控件的构建(8)
    Silverlight中的主题设置
    自定义控件的构建(12)
    自定义控件的构建(7)
    谈谈学完Asp.net 中的自定义控件后的感受
  • 原文地址:https://www.cnblogs.com/cyblogs/p/11295568.html
Copyright © 2011-2022 走看看