liunx windows socket diff

来源:互联网 发布:己知氢气在空气燃烧时 编辑:程序博客网 时间:2024/05/24 06:31

1.头文件

    windows:      #include <process.h> #include <Windows.h>

                           #include <winsock2.h>
                           #pragma comment(lib,"ws2_32.lib")

    linux:             #include <unistd.h> #include <pthread.h>

                           #include <sys/socket.h>
                           #include <netinet/in.h>

2.线程处理

   windows:      _beginthreadex _endthreadex

   linux:            pthread_create   pthread_exit

3.锁

    windows:    CRITICAL_SECTION    gCenterLock;  InitializeCriticalSection(&gCenterLock);   DeleteCriticalSection(&gCenterLock);

    linux:            pthread_mutex_t    gCenterLock;         pthread_mutex_init(&gCenterLock, NULL); pthread_mutex_destroy(&gCenterLock);

4.select

        struct timeval timeout = {3,0};
        fd_set fd;
        FD_ZERO(&fd);
        FD_SET(m_sock,&fd);

    windows:    select(NULL,&fd,NULL,NULL,&timeout);

    linux:           select(m_sock+1,&fd, NULL,NULL,&timeout);     

5.sleep

       windows:  Sleep() ms为单位

       linux:          sleep() s 为单位  usleep() 微秒为单位 





0 0
原创粉丝点击