API同步函数Word文档格式.docx

上传人:b****6 文档编号:18948877 上传时间:2023-01-02 格式:DOCX 页数:81 大小:59.84KB
下载 相关 举报
API同步函数Word文档格式.docx_第1页
第1页 / 共81页
API同步函数Word文档格式.docx_第2页
第2页 / 共81页
API同步函数Word文档格式.docx_第3页
第3页 / 共81页
API同步函数Word文档格式.docx_第4页
第4页 / 共81页
API同步函数Word文档格式.docx_第5页
第5页 / 共81页
点击查看更多>>
下载资源
资源描述

API同步函数Word文档格式.docx

《API同步函数Word文档格式.docx》由会员分享,可在线阅读,更多相关《API同步函数Word文档格式.docx(81页珍藏版)》请在冰豆网上搜索。

API同步函数Word文档格式.docx

htonl(23)

htons(23)

IN_ADDR(24)

inet_addr(24)

inet_ntoa(25)

ioctlsocket(26)

listen(27)

ntohl(28)

ntohs(29)

recv(29)

recvfrom(32)

select(34)

send(36)

sendto(38)

servent(41)

setsockopt(41)

shutdown(47)

sockaddr(49)

sockaddr_atm(49)

sockaddr_gen(51)

socket(51)

SOCKET_ADDRESS(53)

accept

Theacceptfunctionpermitsanincomingconnectionattemptonasocket.

SOCKETaccept(SOCKETs,structsockaddr*addr,int*addrlen);

Parameters

s[in]Descriptoridentifyingasocketthathasbeenplacedinalisteningstatewiththelistenfunction.Theconnectionisactuallymadewiththesocketthatisreturnedbyaccept.

addr[out]Optionalpointertoabufferthatreceivestheaddressoftheconnectingentity,asknowntothecommunicationslayer.TheexactformatoftheaddrparameterisdeterminedbytheaddressfamilythatwasestablishedwhenthesocketfromtheSOCKADDRstructurewascreated.

addrlen[out]Optionalpointertoanintegerthatcontainsthelengthofaddr.

ReturnValuesIfnoerroroccurs,acceptreturnsavalueoftypeSOCKETthatisadescriptorforthenewsocket.Thisreturnedvalueisahandleforthesocketonwhichtheactualconnectionismade.

Otherwise,avalueofINVALID_SOCKETisreturned,andaspecificerrorcodecanberetrievedbycallingWSAGetLastError.

Theintegerreferredtobyaddrleninitiallycontainstheamountofspacepointedtobyaddr.Onreturnitwillcontaintheactuallengthinbytesoftheaddressreturned.

Errorcode

Meaning

WSANOTINITIALISED

AsuccessfulWSAStartupcallmustoccurbeforeusingthisfunction.

WSAENETDOWN

Thenetworksubsystemhasfailed.

WSAEFAULT

Theaddrlenparameteristoosmalloraddrisnotavalidpartoftheuseraddressspace.

WSAEINTR

AblockingWindowsSockets1.1callwascanceledthroughWSACancelBlockingCall.

WSAEINPROGRESS

AblockingWindowsSockets1.1callisinprogress,ortheserviceproviderisstillprocessingacallbackfunction.

WSAEINVAL

Thelistenfunctionwasnotinvokedpriortoaccept.

WSAEMFILE

Thequeueisnonemptyuponentrytoacceptandtherearenodescriptorsavailable.

WSAENOBUFS

Nobufferspaceisavailable.

WSAENOTSOCK

Thedescriptorisnotasocket.

WSAEOPNOTSUPP

Thereferencedsocketisnotatypethatsupportsconnection-orientedservice.

WSAEWOULDBLOCK

Thesocketismarkedasnonblockingandnoconnectionsarepresenttobeaccepted.

Remarks

Theacceptfunctionextractsthefirstconnectiononthequeueofpendingconnectionsonsockets.Itthencreatesandreturnsahandletothenewsocket.Thenewlycreatedsocketisthesocketthatwillhandletheactualconnection;

ithasthesamepropertiesassockets,includingtheasynchronouseventsregisteredwiththeWSAAsyncSelectorWSAEventSelectfunctions.

Theacceptfunctioncanblockthecalleruntilaconnectionispresentifnopendingconnectionsarepresentonthequeue,andthesocketismarkedasblocking.Ifthesocketismarkedasnonblockingandnopendingconnectionsarepresentonthequeue,acceptreturnsanerrorasdescribedinthefollowing.Afterthesuccessfulcompletionofacceptreturnsanewsockethandle,theacceptedsocketcannotbeusedtoacceptmoreconnections.Theoriginalsocketremainsopenandlistensfornewconnectionrequests.

Theparameteraddrisaresultparameterthatisfilledinwiththeaddressoftheconnectingentity,asknowntothecommunicationslayer.Theexactformatoftheaddrparameterisdeterminedbytheaddressfamilyinwhichthecommunicationisoccurring.Theaddrlenisavalue-resultparameter;

itshouldinitiallycontaintheamountofspacepointedtobyaddr;

onreturnitwillcontaintheactuallength(inbytes)oftheaddressreturned.

Theacceptfunctionisusedwithconnection-orientedsockettypessuchasSOCK_STREAM.Ifaddrand/oraddrlenareequaltoNULL,thennoinformationabouttheremoteaddressoftheacceptedsocketisreturned.

NotesforATM

Thefollowingareimportantissuesassociatedwithconnectionsetup,andmustbeconsideredwhenusingAsynchronousTransferMode(ATM)withWindowsSockets2:

TheacceptandWSAAcceptfunctionsdonotnecessarilysettheremoteaddressandaddresslengthparameters.Therefore,whenusingATM,thecallershouldusetheWSAAcceptfunctionandplaceATM_CALLING_PARTY_NUMBER_IEintheProviderSpecificmemberoftheQOSstructure,whichitselfisincludedinthelpSQOSparameterofthecallbackfunctionusedinaccordancewithWSAAccept.

Whenusingtheacceptfunction,realizethatthefunctionmayreturnbeforeconnectionestablishmenthastraversedtheentiredistancebetweensenderandreceiver.ThisisbecausetheacceptfunctionreturnsassoonasitreceivesaCONNECTACKmessage;

inATM,aCONNECTACKmessageisreturnedbythenextswitchinthepathassoonasaCONNECTmessageisprocessed(ratherthantheCONNECTACKbeingsentbytheendnodetowhichtheconnectionisultimatelyestablished).Assuch,applicationsshouldrealizethatifdataissentimmediatelyfollowingreceiptofaCONNECTACKmessage,datalossispossible,sincetheconnectionmaynothavebeenestablishedallthewaybetweensenderandreceiver.

Requirements

Client:

IncludedinWindows 

XP,Windows 

2000Professional,Windows 

NTWorkstation,Windows 

Me,Windows 

98,andWindows 

95.

Server:

IncludedinWindowsServer 

2003,Windows 

2000Server,andWindows 

NTServer.

Header:

DeclaredinWinsock2.h.

Library:

UseWs2_32.lib.

SeeAlsoWindowsSocketsAPIReference,WindowsSocketsFunctions,bind,connect,listen,select,sockaddr,socket,WSAAsyncSelect,WSAAccept

bind

Thebindfunctionassociatesalocaladdresswithasocket.

intbind(SOCKETs,conststructsockaddr*name,intnamelen);

s[in]Descriptoridentifyinganunboundsocket.

name[in]AddresstoassigntothesocketfromtheSOCKADDRstructure.

namelen[in]Lengthofthevalueinthenameparameter,inbytes.

ReturnValuesIfnoerroroccurs,bindreturnszero.Otherwise,itreturnsSOCKET_ERROR,andaspecificerrorcodecanberetrievedbycallingWSAGetLastError.

WSAEACCES

AttempttoconnectdatagramsockettobroadcastaddressfailedbecausesetsockoptoptionSO_BROADCASTisnotenabled.

WSAEADDRINUSE

Aprocessonthecomputerisalreadyboundtothesamefully-qualifiedaddressandthesockethasnotbeenmarkedtoallowaddressreusewithSO_REUSEADDR.Forexample,theIPaddressandportareboundintheaf_inetcase).(SeetheSO_REUSEADDRsocketoptionundersetsockopt.)

WSAEADDRNOTAVAIL

Thespecifiedaddressisnotavalidaddressforthiscomputer.

Thenameornamelenparameterisnotavalidpartoftheuseraddressspace,thenamelenparameteristoosmall,thenameparametercontainsanincorrectaddressformatfortheassociatedaddressfamily,orthefirsttwobytesofthememoryblockspecifiedbynamedoesnotmatchtheaddressfamilyassociatedwiththesocketdescriptors.

Thesocketisalreadyboundtoanaddress.

Notenoughbuffersavailable,toomanyconnections.

Thebindfunctionisusedonanunconnectedsocketbeforesubsequentcallstotheconnectorlistenfunctions.Itisusedtobindtoeitherconnection-oriented(stream)orconnectionless(datagram)sockets.Whenasocketiscreatedwithacalltothesocketfunction,itexistsinanamespace(addressfamily),butithasnonameassignedtoit.Usethebindfunctiontoestablishthelocalassociationofthesocketbyassigningalocalnametoanunnamedsocket.

AnameconsistsofthreepartswhenusingtheInternetaddressfamily:

Theaddressfamily.

Ahostaddress.

Aportnumberthatidentifiestheapplication.

InWindowsSockets2,thenameparameterisnotstrictlyinterpretedasapointertoaSOCKADDRstructure.ItiscastthiswayforWindowsSockets1.1compatibility.Serviceprovidersarefreetoregarditasapointertoablockofmemoryofsizenamelen.Thefirst2bytesinthisblock(correspondingtothesa_familymemberoftheSOCKADDRstructure)mustcontaintheaddressfamilythatwasusedtocreatethesocket.Otherwise,anerrorWSAEFAULToccurs.

Ifanapplicationdoesnotcarewhatlocaladdressisassigned,specifythemanifestconstantvalueADDR_ANYforthesa_datamemberofthenameparameter.Thisallowstheunderlyingserviceprovidertouseanyappropriatenetworkaddress,potentiallysimplifyingapplicationprogramminginthepresenceofmultihomedhosts(thatis,hoststhathavemorethanonenetworkinterfaceandaddress).

ForTCP/IP,iftheportisspecifiedaszero,theserviceproviderassignsauniqueporttotheapplicationwithavaluebetween1024and5000.Theapplicationcanusegetsocknameaftercallingbindtolearntheaddressandtheportthathasbeenassignedtoit.IftheInternetaddressisequaltoINADDR_ANY,getsocknamecannotnecessarilysupplytheaddressuntilthesocketisconnected,sinceseveraladdressescanbevalidifthehostismultihomed.Bindingtoaspecificportnumberotherthanport0isdiscouragedforclientapplications,sincethereisadangerofconflictingwithanothersocketalreadyusingthatportnumber.

Note 

 

WhenusingbindwiththeSO_EXCLUSIVEADDRorSO_REUSEADDRsocketoption,thesocketoptionmustbesetpriortoexecutingbindtohaveanyaffect.

NotesforIrDAS

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高中教育 > 高考

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1