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); }

    ===================================================================================================================================================
  • 相关阅读:
    初步学习css 从css手册看起———text
    IE6双倍margin间距两大解决方案转载
    div+css的基本 常用到语法(一) 。
    初步学习css 从css手册看起———Font
    行内宽高设置无效的解决
    C++面对对象基础
    C++继承和派生
    基于MATLAB的FIR滤波器的设计
    C++多态
    C++中的静态成员和静态函数
  • 原文地址:https://www.cnblogs.com/lihaozy/p/2608712.html
Copyright © 2011-2022 走看看