欢迎来到天天文库
浏览记录
ID:3664987
大小:231.00 KB
页数:35页
时间:2017-11-22
《第5章 基于插口的高级网络编程接口nport》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、第5章基于插口的高级网络编程接口NPORT本章介绍一个高级插口应用编程接口NPORT。NPORT为用户提供一个简化的、方便的高级网络编程接口。5-1概述为了简化TCP和UDP插口编程,我们设计了一个基于插口的高级网络编程插口,NPORT。NPORT的基本思想是将一个TCP连接的两端或UDP通信的双方用一个数据结构来描述,这个数据结构就是NPORT。以此为基础,封装基本的插口函数,简化用户编程。NPORT中记录了与通信双方有关的基本信息,这些信息包括:本地IP地址,本地端口,对等IP地址,对等端口,插口描述符,插口地址域,插口类型,通信模式,插口状态,读写状态。大部分NPORT
2、函数都有一个NPORT类型的传入参数,该参数相当于插口API中的插口描述符参数。5-2基本数据结构NPORTNPORT高级编程接口的头文件nport.h中定义了接口所需的基本数据结构、宏定义和函数原型。头文件的内容如程序5-1所示。程序5-1NPORT编程接口头文件nport.h。1#ifndef_NPORT 2#define_NPORT 3 4#include 5#include 6#include7#include8#include9#include3、socket.h>10#include11#include12#include13#include14#include15#include1617#defineNPORT_MODE_NOBLOCK1第5章基于插口的高级网络编程接口NPORT14318#defineNPORT_MODE_BLOCK019#defineNPORT_NAMELEN322021#defineNPORT_STATE_INIT022#defineNPORT_STATE_OP4、EN123#defineNPORT_STATE_CONN224#defineNPORT_STATE_CLOSE025#defineNPORT_STATE_RCLOSE326#defineNPORT_STATE_WCLOSE42728#defineNPORT_ERROR-129#defineNPORT_DISCONNECTED-230#defineNPORT_NO_DATA_BUF-331#defineNPORT_CALLERROR-432#defineNPORT_SUCCEED03334typedefstruct{35unsignedshortlport;/*本地端口*/365、charlname[NPORT_NAMELEN];/*本地IP地址*/37intsocket;/*本地插口*/38unsignedshortrport;/*对等端口*/39charrname[NPORT_NAMELEN];/*对等IP地址*/40intdomain;/*插口地址域*/41inttype;/*协议类型*/42intmode;/*通信模式*/43charopened;/*插口状态*/44charrflag,wflag,oflag;/*可读标志,可写标志,OOB数据标志*/45}NPORT;46intNPORTInit(NPORT*this); 47intNPORT6、ModeBlock(NPORT*this); 48intNPORTModeNoBlock(NPORT*this); 49intNPORTSOpen(NPORT*this); 50intNPORTCOpen(NPORT*this); 51intNPORTDBOpen(NPORT*this);52intNPORTDOpen(NPORT*this);53intNPORTSPNumber(NPORT*this,intnum);54intNPORTSAccept(NPORT*this,NPORT*conn);55intNPORTCRequest(NPORT*cli);56intNPOR7、TLocalName(NPORT*this,char*name);57intNPORTLocalPort(NPORT*this,unsignedshortport);第5章基于插口的高级网络编程接口NPORT14358intNPORTRemoteName(NPORT*this,char*name);59intNPORTRemotePort(NPORT*this,unsignedshortport);60intNPORTWrtRdy(NPORT*this,intnum,intsec,intusec);61
3、socket.h>10#include11#include12#include13#include14#include15#include1617#defineNPORT_MODE_NOBLOCK1第5章基于插口的高级网络编程接口NPORT14318#defineNPORT_MODE_BLOCK019#defineNPORT_NAMELEN322021#defineNPORT_STATE_INIT022#defineNPORT_STATE_OP
4、EN123#defineNPORT_STATE_CONN224#defineNPORT_STATE_CLOSE025#defineNPORT_STATE_RCLOSE326#defineNPORT_STATE_WCLOSE42728#defineNPORT_ERROR-129#defineNPORT_DISCONNECTED-230#defineNPORT_NO_DATA_BUF-331#defineNPORT_CALLERROR-432#defineNPORT_SUCCEED03334typedefstruct{35unsignedshortlport;/*本地端口*/36
5、charlname[NPORT_NAMELEN];/*本地IP地址*/37intsocket;/*本地插口*/38unsignedshortrport;/*对等端口*/39charrname[NPORT_NAMELEN];/*对等IP地址*/40intdomain;/*插口地址域*/41inttype;/*协议类型*/42intmode;/*通信模式*/43charopened;/*插口状态*/44charrflag,wflag,oflag;/*可读标志,可写标志,OOB数据标志*/45}NPORT;46intNPORTInit(NPORT*this); 47intNPORT
6、ModeBlock(NPORT*this); 48intNPORTModeNoBlock(NPORT*this); 49intNPORTSOpen(NPORT*this); 50intNPORTCOpen(NPORT*this); 51intNPORTDBOpen(NPORT*this);52intNPORTDOpen(NPORT*this);53intNPORTSPNumber(NPORT*this,intnum);54intNPORTSAccept(NPORT*this,NPORT*conn);55intNPORTCRequest(NPORT*cli);56intNPOR
7、TLocalName(NPORT*this,char*name);57intNPORTLocalPort(NPORT*this,unsignedshortport);第5章基于插口的高级网络编程接口NPORT14358intNPORTRemoteName(NPORT*this,char*name);59intNPORTRemotePort(NPORT*this,unsignedshortport);60intNPORTWrtRdy(NPORT*this,intnum,intsec,intusec);61
此文档下载收益归作者所有