⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wal.c

📁 windows 网络编程。pdf文档
💻 C
📖 第 1 页 / 共 5 页
字号:
							as_w_r (hInst, hwnd);
							break;
					}
					break;
				case IDM_READ_WRITE:
					switch (stWSAppData.nOpMode) {
						case OPMODE_BL: 
							bl_r_w (hInst, hwnd);
							break;
						case OPMODE_NB:
							nb_r_w (hInst, hwnd);
						case OPMODE_AS:
							break;	/* see IDM_ASYNC msg */
					}
					break;
				case IDM_WRITE:
					switch (stWSAppData.nOpMode) {
						case OPMODE_BL: 
							bl_w (hInst, hwnd);
							break;
						case OPMODE_NB:
							nb_w (hInst, hwnd);
						case OPMODE_AS:	
							as_w (hInst, hwnd);
							break;
				    }
					break;
				case IDM_READ:
					switch (stWSAppData.nOpMode) {
						case OPMODE_BL: 
							bl_r (hInst, hwnd);
							break;
						case OPMODE_NB:
							nb_r (hInst, hwnd);
							break;
						case OPMODE_AS:
							break;	/* see IDM_ASYNC msg */
					}
					break;
				case IDM_APPOPTIONS:
	    			/*-------------------------
	    			 * Start a new application 
	    			 *------------------------*/
					if (stWSAppData.nSockState > STATE_OPEN) {
						MessageBox (hwnd, "There's a socket open already", 
							"Can't start new application", MB_OK | MB_ICONASTERISK);
					} else {
					
					  lCallCount = 0;	/* init I/O call count to zero */

					  /* run dialog box to get user's WinSock application parameters */	    	
			    	  lpfnWSAppDlgProc = MakeProcInstance((FARPROC)WSAppOptDlgProc,hInst);
					  wRet = DialogBoxParam (hInst, 
							"AppOptionDlg", 
							hwnd, 
							lpfnWSAppDlgProc,
							MAKELPARAM(hInst, hwnd));
					  FreeProcInstance((FARPROC) lpfnWSAppDlgProc);
					
					  /* Reset stats */
					  SendMessage (hwnd, WM_COMMAND, IDM_RESETSTATS, 0L);
					
					  if (wRet) { /* If new app operation not cancelled */
								
						/* Set the Window Title to describe what we're running */
						wsprintf (achOutBuf, "WinSock %s %s %s (port %d)",
							(LPSTR)stWSAppData.szService,
							(LPSTR)((stWSAppData.nProtocol == PROT_DS) ? "stream" : "dgram"),
							(LPSTR)((stWSAppData.nRole == ROLE_CL) ? "client" : "server"),
							stWSAppData.nPortNumber);
						SetWindowText (hwnd, (LPSTR)achOutBuf);
				    
					  	/* User just selected the type of application and our dialog filled-in
					  	 *  our application structure.  Now look at what was selected */
					  	switch (anWSAppTable[stWSAppData.nRole]
										[stWSAppData.nProtocol]
										[stWSAppData.nOpMode]) {
										
                        	/*----- Datastream Clients ----------------------*/
   							case BL_DS_CL:	/* Blocking Datastream Client */
								bl_ds_cn(hInst, hwnd);
								break;
							case NB_DS_CL:	/* Non-blocking Datastream Client */
								nb_ds_cn(hInst, hwnd);
								break;
							case AS_DS_CL:	/* Asynch Datastream Client */
								as_ds_cn(hInst, hwnd);
								break;
						
                        	/*------ Datagram Clients ---------------------*/				
							case BL_DG_CL:  /* Blocking Datagram Client */
								bl_dg_cn(hInst, hwnd);
								break;
							case NB_DG_CL:  /* Non-blocking Datagram Client */
								nb_dg_cn(hInst, hwnd);
								break;
							case AS_DG_CL:  /* Asynch Datagram Client */
								as_dg_cn(hInst, hwnd);
								break;
						
                        	/*------ Datastream Servers -------------------*/
   							case BL_DS_SV:  /* Blocking Datastream Server */
								bl_ds_ls(hInst, hwnd);
								break;
							case NB_DS_SV:  /* Non-blocking Datastream Server */
								nb_ds_ls(hInst, hwnd);
								break;
							case AS_DS_SV:  /* Asynch Datastream Server */
								as_ds_ls(hInst, hwnd);
								break;
						
                        	/*------ Datagram Servers --------------------*/
							case BL_DG_SV:  /* Blocking Datagram Server */
								bl_dg_ls(hInst, hwnd);
								break;
							case NB_DG_SV:  /* Non-Blocking Datagram Server */
								nb_dg_ls(hInst, hwnd);
								break;
							case AS_DG_SV:  /* Asynch Datagram Server */
								as_dg_ls(hInst, hwnd);
								break;
						  }
					  	}
					}
					break;
				
				case IDM_OPENSOCK:
				    /*---------------------------------------------------------
				     * Dialog box to prompt for socket type, then get a socket 
				     *---------------------------------------------------------*/
        			/* If we already have a socket open, tell them to close it first */
        			if (stWSAppData.nSockState != STATE_NONE) {
        				MessageBox (hwnd, "There's a socket open already", "Can't open a socket", 
        					MB_OK | MB_ICONASTERISK);
        			} else {
			    		lpfnWSOptionProc = MakeProcInstance((FARPROC)WSSocketDlgProc, hInst);
						DialogBoxParam (hInst, 
							"SocketDlg", 
							hwnd, 
							lpfnWSOptionProc,
							MAKELPARAM(hInst, hwnd));
						FreeProcInstance((FARPROC) lpfnWSOptionProc);
					}
					break;
										               
				case IDM_ABORTSOCK:	      
				case IDM_CLOSESOCK:
	    			/*------------------------------------------------------------------
	    			 * Close the socket (if we have one and close not already requested)
	    			 *-----------------------------------------------------------------*/
	    			if ((stWSAppData.nSockState != STATE_NONE) &&
	    				(stWSAppData.nSockState != STATE_CLOSE_PENDING))
	    				return (do_close(hInst, hwnd, lParam));
	    			break;
	    			
				case IDM_IOOPTIONS:
					 /*----------------------------------
					  * Dialog box to change I/O options
					  *----------------------------------*/
					 lpfnWSOptionProc = MakeProcInstance((FARPROC)WSIOOptDlgProc, hInst);
					 DialogBoxParam (hInst,
					 		"IOOptionDlg",
					 		hwnd,
					 		lpfnWSOptionProc,
					 		MAKELPARAM(hInst, hwnd));
					 FreeProcInstance((FARPROC) lpfnWSOptionProc);
					 break;
					 
				case IDM_OOBOPTIONS:
					/*-----------------------------------------
					 * Dialog box to change application options
					 *----------------------------------------*/
			    	lpfnWSOptionProc = MakeProcInstance((FARPROC)WSOobOptDlgProc, hInst);
					DialogBoxParam (hInst, 
							"OobOptionDlg", 
							hwnd, 
							lpfnWSOptionProc,
							MAKELPARAM(hInst, hwnd));
					FreeProcInstance((FARPROC) lpfnWSOptionProc);

					break;

				case IDM_SOCKOPTIONS:
					/*---------------------------------
					 * Dialog box to get socket options
					 *---------------------------------*/
			    	lpfnWSOptionProc = MakeProcInstance((FARPROC)WSSockOptDlgProc, hInst);
					DialogBoxParam (hInst, 
							"SockOptionDlg", 
							hwnd, 
							lpfnWSOptionProc,
							MAKELPARAM(hInst, hwnd));
					FreeProcInstance((FARPROC) lpfnWSOptionProc);

					break;
				
	    		case IDM_RESETSTATS:
					/*------------------
					 * Reset statistics
					 *----------------*/
					stWSAppData.lBytesOut 	= 0;	/* reset send byte count */
					stWSAppData.lBytesIn	= 0;	/* reset receive byte count */
					stWSAppData.wOffset 	= 0;	/* start with first char in sequence */
					stWSAppData.lCallCount	= 0;	/* reset numberof I/O calls so far */
					stWSAppData.lSeconds	= 1;	/* reset time elapsed */
					stWSAppData.nLoopsUp	= 0;	/* reset loop adjustment counters */
					stWSAppData.nLoopsDn	= 0;
					stWSAppData.nLoopLimit  = stWSAppData.nLoopMax;	/* put loop at limit */
					stWSAppData.lStartTime 	= GetTickCount();		/* new start time */
					
					do_stats(hwnd, hInst, FALSE);

	    			break;
					
				case IDM_SHOWSTATS:
					/*---------------------------
					 * Update statistics display
					 *--------------------------*/
					do_stats(hwnd, hInst, FALSE);
					break;
					
				case IDM_DETAILSTATS:
					/*---------------------------------------
					 * Show Local & Remote Sockname w/ stats
					 *--------------------------------------*/
					bShowDetail = !bShowDetail;	/* toggle detail on/off switch */
					hWalMenu = GetMenu(hwnd); 	/*  check the menu to show setting */
					CheckMenuItem (hWalMenu, 
						IDM_DETAILSTATS,
						MF_BYCOMMAND | (bShowDetail ? MF_CHECKED : MF_UNCHECKED));
					do_stats(hwnd, hInst, TRUE);	/* update stats display */
					break;
					
				case IDM_NEWLOG:
				case IDM_CLOSELOG:
					MessageBox (hwnd, "Not implemented yet", "Error",
						MB_OK | MB_ICONASTERISK);
					break;
					
		    	case IDM_ABOUT:
 		    		DialogBox (hInst, MAKEINTRESOURCE(IDD_ABOUT), hwnd, Dlg_About);
 		      		break;
 		      		
 		      	case IDM_EXIT:
 		      		PostMessage(hwnd, WM_CLOSE, 0, 0L);
					break;
					 		    		
 		    	default:
 		    		return (DefWindowProc(hwnd, msg, wParam, lParam));
 		    		
        	} /* end case WM_COMMAND: */
       		break;
       		
		case WM_PAINT:
			do_stats (hwnd, hInst, FALSE);
			break;
                    
		case WM_TIMER:
			/*-------------------------------------------
			 * Process stats display and I/O timer events
			 *-------------------------------------------*/
			switch (wParam) {
				case (STATS_TIMER_ID):
					do_stats (hwnd, hInst, FALSE);
					break;
                    
				case (APP_TIMER_ID):
				    /*
				     *  Post ourselves message to do I/O
				     *   (if we're connected, and not already doing something)
				     */
        	        if ((stWSAppData.nSockState == STATE_CONNECTED) && !WSAIsBlocking())
						PostMessage(hwnd, WM_COMMAND, anIoCmd[stWSAppData.nIoMode], 0L);
					break;
					
			} /* end case WM_TIMER */
        	break;

	    case WM_QUERYENDSESSION:
        case WM_CLOSE:
			/*------------------
			 * Close the Socket
			 *-----------------*/
            /* Ask if user wants to close connection before we leave */
        	if (!SendMessage(hwnd, WM_COMMAND, IDM_CLOSESOCK, 1L)) {
 				/* Send WM_DESTROY & WM_NCDESTROY to main window */  
            	DestroyWindow(hwnd);
            }
            break;

        case WM_CREATE:
	    	/* save instance handle */
	    	hInst = ((LPCREATESTRUCT) lParam)->hInstance;
	    	
 			/* Default (96) is # ASCII chars displayed (to get barberpole on screen)
  			 *  we'll use the size the user wants, if they enter a new value */
  			cbBufSize = DFLT_BYTES_PER_IO;
  			                                                                               
  			/*------------load string into our work buffer---------- */
 			LoadString (hInst, CHARGEN_SEQ, achInBuf, BUF_SIZE);	/* get our char string */
  			i = (2*BUF_SIZE) / cbBufSize;	/* number of iterations we need to copy string */
   			for (j=0; i > 0; i--, j+=cbBufSize) {	/* fill chargen buf w/ repeated char series */
   				_fmemcpy((LPSTR)&(achChargenBuf[j]), (LPSTR)achInBuf, cbBufSize);
   			}
   			i = (2*BUF_SIZE) % cbBufSize;	/* to finish, fill remainder of buffer (if any) */
   			if (i) {
   				j = ((2*BUF_SIZE) / cbBufSize) * cbBufSize;
   				_fmemcpy ((LPSTR)&(achChargenBuf[j]), (LPSTR)achInBuf, i);
   			}

			/* assign application default option values (from WAL.INI, if available) */
			stWSAppData.nSockState 	= STATE_NONE;		/* socket is a non-entity yet */
			stWSAppData.nOutLen		= 0;
			stWSAppData.lSeconds	= 1L;
			stWSAppData.nProtocol	= GetPrivateProfileInt(
				/* Protocol: Datastream or Datagram */
				(LPSTR)szAppOption, "Protocol", PROT_DS, szIniFile);
			stWSAppData.nRole 		= GetPrivateProfileInt(
				/* Role: Client or Server */
				(LPSTR)szAppOption, "Role", ROLE_CL, szIniFile);
			stWSAppData.nOpMode 		= GetPrivateProfileInt(
				/* Operation mode: blocking, non-blocking, or asynch*/
				(LPSTR)szAppOption, "Mode", OPMODE_BL, szIniFile);
			stWSAppData.nIoMode 		= GetPrivateProfileInt(
				/* I/O Mode (per op mode): read/write, write/read, read-only or write-only */
				(LPSTR)astOpModeOption[stWSAppData.nOpMode].szSection, 
				"IoMode", 
				astOpModeOption[stWSAppData.nOpMode].nIoMode, 
				szIniFile);
			stWSAppData.nLength 	= GetPrivateProfileInt(
				/* bytes to read and/or write each i/o */
				(LPSTR)astOpModeOption[stWSAppData.nOpMode].szSection,
				"BytesPerIo", 
				astOpModeOption[stWSAppData.nOpMode].nLength, 
				szIniFile);
			stWSAppData.nLoopLimit 	= GetPrivateProfileInt(
				/* number of i/o iterations each loop */
				(LPSTR)astOpModeOption[stWSAppData.nOpMode].szSection,
				"IoPerLoop", 
				astOpModeOption[stWSAppData.nOpMode].nLoopLimit, 
				szIniFile);
			stWSAppData.nWinTimer 	= GetPrivateProfileInt(
				/* time between loops (0 if timer not used) */
				(LPSTR)astOpModeOption[stWSAppData.nOpMode].szSection,
				"LoopInterval", 
				astOpModeOption[stWSAppData.nOpMode].nWinTimer, 
				szIniFile);
			stWSAppData.nBytesMax 	= (u_short) GetPrivateProfileInt(
				/* maximum number of bytes to transfer */
				(LPSTR)astOpModeOption[stWSAppData.nOpMode].szSection,
				"BytesToXfer", 
				astOpModeOption[stWSAppData.nOpMode].nBytesMax, 
				szIniFile);
			stWSAppData.nPortNumber = (u_short) GetPrivateProfileInt(
				/* defualt port number */
				(LPSTR)astOpModeOption[stWSAppData.nOpMode].szSection,
				"PortNumber",
				astIoModeOption[stWSAppData.nOpMode][stWSAppData.nRole].nPortNumber, 
				szIniFile);
			GetPrivateProfileString(
				/* default service name */
				(LPSTR)astOpModeOption[stWSAppData.nOpMode].szSection,
				"ServiceName", 
				astIoModeOption[stWSAppData.nIoMode][stWSAppData.nOpMode].szService,
				(LPSTR)stWSAppData.szService, 
				MAX_NAME_SIZE, 
				szIniFile);
			GetPrivateProfileString(
				/* default (remote) hostname or IP address */
				(LPSTR)astOpModeOption[stWSAppData.nOpMode].szSection,
				"Host", 
				"",
				(LPSTR)stWSAppData.szHost, 
				MAX_NAME_SIZE, 
				szIniFile);
			/* Note: Some of these should be added to the .INI file, 
			 *  including the Send, Poll, InOobSound, and OutOobSound options */
			stWSAppData.lOobBytesOut= 0;
			stWSAppData.lOobBytesIn = 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -