zoukankan      html  css  js  c++  java
  • ioctlsocket的作用

    ioctlsocket is short for io control socket,也就是指示SOCKET的IO mode.可以为阻塞或者非阻塞.

    以下代码copy from MSDN。代码中iMode参数指示了阻塞或者非阻塞的模式。




    ===================================================================================================================================================

    #include <winsock2.h> #include <stdio.h> #pragma comment(lib, "Ws2_32.lib") void main() { //------------------------- // Initialize Winsock WSADATA wsaData; int iResult; u_long iMode = 0; iResult = WSAStartup(MAKEWORD(2,2), &wsaData); if (iResult != NO_ERROR) printf("Error at WSAStartup()\n"); //------------------------- // Create a SOCKET object. SOCKET m_socket; m_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (m_socket == INVALID_SOCKET) { printf("Error at socket(): %ld\n", WSAGetLastError()); WSACleanup(); return; } //------------------------- // Set the socket I/O mode: In this case FIONBIO // enables or disables the blocking mode for the // socket based on the numerical value of iMode. // If iMode = 0, blocking is enabled; // If iMode != 0, non-blocking mode is enabled. iResult = ioctlsocket(m_socket, FIONBIO, &iMode); if (iResult != NO_ERROR) printf("ioctlsocket failed with error: %ld\n", iResult); }

    ===================================================================================================================================================
  • 相关阅读:
    hdu 3746 Cyclic Nacklace
    hdu 3336 Count the string
    hdu 1358 Period
    hiho一下 第一周 最长回文子串
    KMP算法详解
    Java 之 static的使用方法(6)
    Jave 之方法-函数(5)
    Java 之数组(4)
    大数据-storm学习资料视频
    大数据-spark-hbase-hive等学习视频资料
  • 原文地址:https://www.cnblogs.com/lihaozy/p/2608712.html
Copyright © 2011-2022 走看看