WSP函数.docx
《WSP函数.docx》由会员分享,可在线阅读,更多相关《WSP函数.docx(151页珍藏版)》请在冰豆网上搜索。
WSP函数
WSP函数
WSPAccept
(1)
WSPAddressToString(4)
WSPAsyncSelect(5)
WSPBind(11)
WSPCancelBlockingCall(13)
WSPCleanup(14)
WSPCloseSocket(15)
WSPConnect(17)
WSPDATA(20)
WSPDuplicateSocket(20)
WSPEnumNetworkEvents(23)
WSPEventSelect(25)
Headerand.IdlFilesProvidedwithISA(28)
WSPGetOverlappedResult(29)
WSPGetPeerName(31)
WSPGetQOSByName(32)
WSPGetSockName(33)
WSPGetSockOpt(34)
WSPIoctl(37)
WSPJoinLeaf(45)
WSPListen(48)
WSPRecv(50)
WSPRecvDisconnect(54)
WSPRecvFrom(55)
wsprintfFunction(60)
WSProxyAddressProperty(62)
WSProxyPortProperty(63)
WSPSelect(63)
WSPSend(66)
WSPSendDisconnect(69)
WSPSendTo(70)
WSPSetSockOpt(74)
WSPShutdown(77)
WSPSocket(78)
WSPStartup(80)
WSPStringToAddress(84)
WSPAccept
TheWSPAcceptfunctionconditionallyacceptsaconnectionbasedonthereturnvalueofaconditionfunction.
SOCKETWSPAccept(SOCKETs,structsockaddr*addr,LPINTaddrlen,LPCONDITIONPROClpfnCondition,DWORDdwCallbackData,LPINTlpErrno);
Parameters
s[in]DescriptoridentifyingasocketthatislisteningforconnectionsafteraWSPListen.
addr[out]Optionalpointertoabufferthatreceivestheaddressoftheconnectingentity,asknowntotheserviceprovider.TheexactformatoftheaddrparameterisdeterminedbytheaddressfamilyestablishedwhenthesocketintheSOCKADDRstructurewascreated.
addrlen[in,out]Optionalpointertoanintegerthatcontainsthelengthoftheaddrparameter,inbytes.
lpfnCondition[in]Procedureinstanceaddressofanoptional-conditionfunctionfurnishedbyWindowsSockets.Thisfunctionisusedintheacceptorrejectdecisionbasedonthecallerinformationpassedinasparameters.
dwCallbackData[in]CallbackdatatobepassedbacktotheWindowsSocket2clientasthevalueofthedwCallbackDataparameteroftheconditionfunction.Thisparameterisnotinterpretedbytheserviceprovider.
lpErrno[out]Pointertotheerrorcode.
ReturnValuesIfnoerroroccurs,WSPAcceptreturnsavalueoftypeSOCKETthatisadescriptorfortheacceptedsocket.Otherwise,avalueofINVALID_SOCKETisreturned,andaspecificerrorcodeisavailableinlpErrno.
Errorcode
Meaning
WSAECONNREFUSED
Theconnectionrequestwasforcefullyrejectedasindicatedinthereturnvalueoftheconditionfunction(CF_REJECT).
WSAENETDOWN
Thenetworksubsystemhasfailed.
WSAEFAULT
TheaddrlenparameteristoosmallorthelpfnConditionparameterisnotpartoftheuseraddressspace.
WSAEINTR
A(blocking)callwascanceledthroughWSPCancelBlockingCall.
WSAEINPROGRESS
AblockingWindowsSocketscallisinprogress.
WSAEINVAL
WSPListenwasnotinvokedpriortoWSPAccept,parametergspecifiedintheconditionfunctionisnotavalidvalue,thereturnvalueoftheconditionfunctionisnotavalidone,oranycasewherethespecifiedsocketisinaninvalidstate.
WSAEMFILE
QueueisnonemptyuponentrytoWSPAcceptandtherearenosocketdescriptorsavailable.
WSAENOBUFS
Nobufferspaceisavailable.
WSAENOTSOCK
Thedescriptorisnotasocket.
WSAEOPNOTSUPP
Referencedsocketisnotatypethatsupportsconnection-orientedservice.
WSATRY_AGAIN
Acceptanceoftheconnectionrequestwasdeferredasindicatedinthereturnvalueoftheconditionfunction(CF_DEFER).
WSAEWOULDBLOCK
Socketismarkedasnonblockingandnoconnectionsarepresenttobeaccepted.
WSAEACCES
Theconnectionrequestthatwasofferedhastimedoutorbeenwithdrawn.
Remarks
TheWSPAcceptfunctionextractsthefirstconnectiononthequeueofpendingconnectionsonsockets,andchecksitagainsttheconditionfunction,providedtheconditionfunctionisspecified(thatis,notnull).Theconditionfunctionmustbeexecutedinthesamethreadasthisroutine.IftheconditionfunctionreturnsCF_ACCEPT,WSPAcceptcreatesanewsocket.
Newlycreatedsocketshavethesamepropertiesasthesockets,includingnetworkeventsregisteredwithWSPAsyncSelectorwithWSPEventSelect.AsdescribedinDescriptorAllocation,whennewsocketdescriptorsareallocated,IFSprovidersmustcallWPUModifyIFSHandleandnon-IFSprovidersmustcallWPUCreateSocketHandle.
IftheconditionfunctionreturnsCF_REJECT,WSPAcceptrejectstheconnectionrequest.Iftheapplication'saccept/rejectdecisioncannotbemadeimmediately,theconditionfunctionwillreturnCF_DEFERtoindicatethatnodecisionhasbeenmade.Noactionaboutthisconnectionrequestistobetakenbytheserviceprovider.Whentheapplicationisreadytotakeactionontheconnectionrequest,itwillinvokeWSPAcceptagainandreturneitherCF_ACCEPTorCF_REJECTasareturnvaluefromtheconditionfunction.
Forsocketsthatareinthe(default)blockingmode,ifnopendingconnectionsarepresentonthequeue,WSPAcceptblocksthecalleruntilaconnectionispresent.Forsocketsinnonblockingmode,ifthisfunctioniscalledwhennopendingconnectionsarepresentonthequeue,WSPAcceptreturnstheerrorcodeWSAEWOULDBLOCK.Theacceptedsocketcannotbeusedtoacceptmoreconnections.Theoriginalsocketremainsopen.
Theparameteraddrisaresultparameterthatisfilledwiththeaddressoftheconnectingentity,asknowntotheserviceprovider.Theexactformatoftheaddrparameterisdeterminedbytheaddressfamilyinwhichthecommunicationisoccurring.Theaddrlenisavalue-resultparameter;itwillinitiallycontaintheamountofspacepointedtobyaddr.Onreturn,itmustcontaintheactuallength(inbytes)oftheaddressreturnedbytheserviceprovider.Thiscallisusedwithconnection-orientedsockettypessuchasSOCK_STREAM.Ifaddrand/oraddrlenareequaltonull,thennoinformationabouttheremoteaddressoftheacceptedsocketisreturned.Otherwise,thesetwoparametersshallbefilledinregardlessofwhethertheconditionfunctionisspecifiedorwhatitreturns.
Theprototypeoftheconditionfunctionisasfollows:
intCALLBACKConditionFunc(INLPWSABUFlpCallerId,INLPWSABUFlpCallerData,INOUTLPQOSlpSQOS,INOUTLPQOSlpGQOS,INLPWSABUFlpCalleeId,INLPWSABUFlpCalleeData,OUTGROUPFAR*g,INDWORDdwCallbackData);
ThelpCallerIdandlpCallerDataarevalueparametersthatmustcontaintheaddressoftheconnectingentityandanyuserdatathatwassentalongwiththeconnectionrequest.Ifnocalleridentifierorcallerdataisavailable,thecorrespondingparameterwillbenull.Manynetworkprotocolsdonotsupportconnect-timecallerdata.Mostconventionalnetworkprotocolscanbeexpectedtosupportcalleridentifierinformationatconnection-requesttime.ThebufpartoftheWSABUFpointedtobylpCallerIdpointstoaSOCKADDR.TheSOCKADDRisinterpretedaccordingtoitsaddressfamily(typicallybycastingtheSOCKADDRtosometypespecifictotheaddressfamily).
ThelpSQOSparameterreferencestheflowspecificationsforsocketsspecifiedbythecaller,oneforeachdirection,followedbyanyadditionalprovider-specificparameters.Thesendingorreceivingflowspecificationvalueswillbeignoredasappropriateforanyunidirectionalsockets.AnullvalueforlpSQOSindicatesthatthereisnocaller-suppliedQOSandthatnonegotiationispossible.Anon-NULLlpSQOSpointerindicatesthataQOSnegotiationistooccurorthattheproviderispreparedtoaccepttheQOSrequestwithoutnegotiation.
ThelpCalleeIdisavalueparameterthatcontainsthelocaladdressoftheconnectedentity.ThebufpartoftheWSABUFpointedtobylpCalleeIdpointstoaSOCKADDR.TheSOCKADDRisinterpretedaccordingtoitsaddressfamily(typicallybycastingtheSOCKADDRtosometypespecifictotheaddressfamily).
ThelpCalleeDataisaresultparameterusedbytheconditionfunctiontosupplyuserdatabacktotheconnectingentity.Thestorageforthisdatamustbeprovidedbytheserviceprovider.ThelpCalleeData->leninitiallycontainsthelengthofthebufferallocatedbytheserviceproviderandpointedtobylpCalleeData->buf.Avalueofzeromeanspassinguserdatabacktothecallerisnotsupported.TheconditionfunctionwillcopyuptolpCalleeData->lenbytesofdataintolpCalleeData->buf,andthenupdatelpCalleeData->lentoindicatetheactualnumberofbytestransferred.Ifnouserdataistobepassedbacktothecaller,theconditionfunctionwillsetlpCalleeData->lentozero.Theformatofalladdressanduserdataisspecifictotheaddressfamilytowhichthesocketbelongs.
ThedwCallbackDataparametervaluepassedtotheconditionfunctionisthevaluepassedasthedwCallbackDataparameterintheoriginalWSPAcceptcall.ThisvalueisinterpretedonlybytheWindowsSockets2client.ThisallowsaclienttopasssomecontextinformationfromtheWSPAcceptcallsitethroughtotheconditionfunction,whichprovidestheconditionfunctionwithanyadditionalinformationrequiredtodeterminewhethertoaccepttheconnection.Atypicalusageistopassa(suitablycast)pointertoadatastructurecontainingreferencestoapplication-definedobjectswithwhichthissocketisassociated.
Requirements
Client:
IncludedinWindows XP,Windows 2000Professional,andWindows NTWorkstation3.51andlater.
Server:
IncludedinWindowsServer 2003,Windows 2000Server,andWindows NTServer3.51andlater.
Header:
DeclaredinWs2spi.h.
SeeAlsoWSPAccept,WSPBind,WSPConnect,WSPGetSockOpt,WSPListen,WSPSelect,WSPSocket,WSPAsyncSelect,WSPEventSelect
WSPAddressToString
TheWSPAddressToStringfunctionconvertsallcomponentsofaSOCKADDRstructureintoahumanreadable–numericstringrepresentationoftheaddress.Thisisusedmainlyfordisplaypurposes.
intWSPAddressToString(LPSOCKADDRlpsaAddress,DWORDdwAddressLength,LPWSAPROTOCOL_INFOlpProtocolInfo,LPWSTRlpszAddressString,LPDWORDlpdwAddressStringLength,LPINTlpErrno);
Parameters
lpsaAddress[in]PointertoaSOCKADDRstructuretotranslate