Dab tsi yog qhov tsis thaiv qhov (socket)?
Dab tsi yog qhov tsis thaiv qhov (socket)?

Video: Dab tsi yog qhov tsis thaiv qhov (socket)?

Video: Dab tsi yog qhov tsis thaiv qhov (socket)?
Video: Ua Dab Tsi Txhaum Koj - David Yang (New Song 2021) 2024, Tej zaum
Anonim

tsis yog - thaiv cov qhov (socket) .. Txoj kev daws teeb meem no hu ua " tsis yog - thaiv cov qhov (socket) .". Los ntawm lub neej ntawd, TCP cov qhov (socket) . nyob hauv " thaiv " hom. Piv txwv li, thaum koj hu rau recv() nyeem los ntawm cov kwj, kev tswj tsis rov qab mus rau koj qhov kev pab cuam kom txog thaum tsawg kawg ib byte ntawm cov ntaub ntawv tau nyeem los ntawm qhov chaw nyob deb.

Yog li ntawd, dab tsi yog thaiv thiab tsis thaiv qhov (socket)?

Hauv thaiv hom, recv, xa, txuas (TCP nkaus xwb) thiab lees txais (TCP nkaus xwb) lub qhov (socket) . API hu yuav thaiv indefinitely kom txog thaum qhov kev thov tau ua tiav. Hauv tsis yog - thaiv hom, cov haujlwm no rov qab tam sim ntawd. xaiv yuav thaiv mus txog qhov lub qhov (socket) . npaj txhij.

Ib tug kuj yuav nug, yog cov sockets thaiv los ntawm lub neej ntawd? Los ntawm ua ntej , TCP cov qhov (socket) . muab tso rau hauv a thaiv hom. Qhov no txhais tau tias kev tswj tsis tau rov qab mus rau koj qhov kev pab cuam kom txog thaum qee qhov haujlwm tshwj xeeb tiav.

Hais txog qhov no, koj yuav ua li cas thiaj tsis thaiv qhov (socket)?

Kos ib lub qhov (socket) . raws li tsis yog - thaiv , peb siv fcntl system hu. Nov yog ib qho piv txwv: int flags = guard(fcntl(socket_fd, F_GETFL), "tsis tuaj yeem tau txais cov chij"); guard(fcntl(socket_fd, F_SETFL, chij | O_NONBLOCK), "tsis tuaj yeem teeb cov ntaub ntawv chij");

Qhov thaiv qhov (socket) yog dab tsi?

A lub qhov (socket) . tuaj yeem nyob hauv " thaiv hom "los yog" tsis thaiv hom "Cov haujlwm ntawm cov qhov (socket) . hauv thaiv (los yog synchronous) hom tsis txhob rov qab mus txog thaum lawv tuaj yeem ua tiav lawv cov haujlwm. Qhov no hu ua thaiv vim cov lub qhov (socket) . uas nws lub luag haujlwm hu ua tsis tuaj yeem ua dab tsi - raug thaiv - txog thaum hu rov qab.

Pom zoo: