sizeof(s)/sizeof(s[0]

使用在这里面的:for(i=0;i<sizeof(s)/sizeof(s[0]);i++)

sizeof(s)/sizeof(s[0])
sizeof(s)是一个数组总共的字节数哈
sizeof(s[0]就是一个元素占的字节数
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
#include <winsock2.h> #include <MSTcpIP.h> #pragma comment(lib,"ws2_32.lib") #include "Buffer.h" #include "CpuUsage.h" #include <process.h> #include <afxtempl.h> //////////////////////////////////////////////////////////////////// #define NC_CLIENT_CONNECT 0x0001 #define NC_CLIENT_DISCONNECT 0x0002 #define NC_TRANSMIT 0x0003 #define NC_RECEIVE 0x0004 #define NC_RECEIVE_COMPLETE 0x0005 // 完整接收 class CLock { public: CLock(CRITICAL_SECTION& cs, const CString& strFunc) { m_strFunc = strFunc; m_pcs = &cs; Lock(); } ~CLock() { Unlock(); } void Unlock() { LeaveCriticalSection(m_pcs); TRACE(_T("LC %d %s\n") , GetCurrentThreadId() , m_strFunc); } void Lock() { TRACE(_T("EC %d %s\n") , GetCurrentThreadId(), m_strFunc); EnterCriticalSection(m_pcs); } protected: CRITICAL_SECTION* m_pcs; CString m_strFunc; }; enum IOType { IOInitialize, IORead, IOWrite, IOIdle }; class OVERLAPPEDPLUS { public: OVERLAPPED m_ol; IOType m_ioType; OVERLAPPEDPLUS(IOType ioType) { ZeroMemory(this, sizeof(OVERLAPPEDPLUS)); m_ioType = ioType; } }; //lang2.1_3 struct ClientContext //简单分析ClientContext结构体然后回到 SendSelectCommand { SOCKET m_Socket; //套接字 // Store buffers CBuffer m_WriteBuffer; CBuffer m_CompressionBuffer; // 接收到的压缩的数据 CBuffer m_DeCompressionBuffer; // 解压后的数据 CBuffer m_ResendWriteBuffer; // 上次发送的数据包,接收失败时重发时用 int m_Dialog[2]; // 放对话框列表用,第一个int是类型,第二个是CDialog的地址 int m_nTransferProgress; // Input Elements for Winsock WSABUF m_wsaInBuffer; BYTE m_byInBuffer[8192]; // Output elements for Winsock WSABUF m_wsaOutBuffer; HANDLE m_hWriteComplete; // Message counts... purely for example purposes LONG m_nMsgIn; LONG m_nMsgOut; BOOL m_bIsMainSocket; // 是不是主socket ClientContext* m_pWriteContext; ClientContext* m_pReadContext; }; template<> inline UINT AFXAPI HashKey(CString & strGuid) { return HashKey( (LPCTSTR) strGuid); } #include "Mapper.h" typedef void (CALLBACK* NOTIFYPROC)(LPVOID, ClientContext*, UINT nCode); typedef CList<ClientContext*, ClientContext* > ContextList; class CMainFrame; class CIOCPServer { public: void DisconnectAll(); CIOCPServer(); virtual ~CIOCPServer(); NOTIFYPROC m_pNotifyProc; CMainFrame* m_pFrame; bool Initialize(NOTIFYPROC pNotifyProc, CMainFrame* pFrame, int nMaxConnections, int nPort); static unsigned __stdcall ListenThreadProc(LPVOID lpVoid); static unsigned __stdcall ThreadPoolFunc(LPVOID WorkContext); static CRITICAL_SECTION m_cs; void Send(ClientContext* pContext, LPBYTE lpData, UINT nSize); void PostRecv(ClientContext* pContext); bool IsRunning(); void Shutdown(); void ResetConnection(ClientContext* pContext); LONG m_nCurrentThreads; LONG m_nBusyThreads; UINT m_nSendKbps; // 发送即时速度 UINT m_nRecvKbps; // 接受即时速度 UINT m_nMaxConnections; // 最大连接数 protected: void InitializeClientRead(ClientContext* pContext); BOOL AssociateSocketWithCompletionPort(SOCKET device, HANDLE hCompletionPort, DWORD dwCompletionKey); void RemoveStaleClient(ClientContext* pContext, BOOL bGraceful); void MoveToFreePool(ClientContext *pContext); ClientContext* AllocateContext(); LONG m_nWorkerCnt; bool m_bInit; bool m_bDisconnectAll; BYTE m_bPacketFlag[5]; void CloseCompletionPort(); void OnAccept(); bool InitializeIOCP(void); void Stop(); ContextList m_listContexts; ContextList m_listFreePool; WSAEVENT m_hEvent; SOCKET m_socListen; HANDLE m_hKillEvent; HANDLE m_hThread; HANDLE m_hCompletionPort; bool m_bTimeToKill; CCpuUsage m_cpu; LONG m_nKeepLiveTime; // 心跳超时 // Thread Pool Tunables LONG m_nThreadPoolMin; LONG m_nThreadPoolMax; LONG m_nCPULoThreshold; LONG m_nCPUHiThreshold; CString GetHostName(SOCKET socket); void CreateStream(ClientContext* pContext); BEGIN_IO_MSG_MAP() IO_MESSAGE_HANDLER(IORead, OnClientReading) IO_MESSAGE_HANDLER(IOWrite, OnClientWriting) IO_MESSAGE_HANDLER(IOInitialize, OnClientInitializing) END_IO_MSG_MAP() bool OnClientInitializing (ClientContext* pContext, DWORD dwSize = 0); bool OnClientReading (ClientContext* pContext, DWORD dwSize = 0); bool OnClientWriting (ClientContext* pContext, DWORD dwSize = 0); };
//--------------------------------------------------------------------------- // Net MAIN.C // // 8051 Web Server project // See Makefile for build notes // Written for Keil C51 V5.1 compiler, notes: // It uses big endian order, which is the same as the // network byte order, unlike x86 systems. // Use OPTIMIZE(2)or higher so that automatic variables get shared // between functions, to stay within the 256 bytes idata space //--------------------------------------------------------------------------- #include #include #include "89E564RD.H" #include "net.h" #include "eth.h" #include "serial.h" #include "timer.h" #include "arp.h" #include "tcp.h" #include "http.h" #include "ip.h" // Global variables unsigned int volatile event_word; unsigned char idata debug; unsigned char idata rcve_buf_allocated; char xdata text[20]; // This sets my hardware address to 00:01:02:03:04:05 unsigned char code my_hwaddr[6] = {0x52, 0x54, 0x4c, 0xbb, 0x50, 0xd8}; // Hardware addr to send a broadcast unsigned char code broadcast_hwaddr[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; // This sets my IP address to 192.168.0.168 unsigned long code my_ipaddr = 0xC0A800A8L; // This sets my subnet mask to 255.255.255.0 unsigned long code my_subnet = 0xFFFFFF00L; // Set to 0 if no gateway is present on network // unsigned long code gateway_ipaddr = 0; // This sets my gateway address to 192.168.0.1 unsigned long code gateway_ipaddr = 0xC0A80001L; //-------------------------------------------------------------------------- // Initialize the memory management routines // Initialize variables declared in main //-------------------------------------------------------------------------- unsigned int Count1msInc; unsigned char Count1ms,Count10ms,Count1s; unsigned char TimeSecond,TimeMinute; /***************************************************************************************** ** 函数名称: init_main(void) ** 功能描述: 主函数初始化 ** 调用参数: 无 ** 返回参数: 无 ** 调用模块: init_mempool((vo

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值