Skip to content

Instantly share code, notes, and snippets.

@tawashichan
Created December 9, 2019 04:36
Show Gist options
  • Select an option

  • Save tawashichan/9dc95a6d79ff2fd22db1a41106fc1a31 to your computer and use it in GitHub Desktop.

Select an option

Save tawashichan/9dc95a6d79ff2fd22db1a41106fc1a31 to your computer and use it in GitHub Desktop.

Revisions

  1. tawashichan created this gist Dec 9, 2019.
    24 changes: 24 additions & 0 deletions hyper_memo.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    - 共通

    - Executorというtraitをimplする型が,tokioのtaskをspawnする責務を担っている(よってhyperはtokio runtimeでないと動かない)。ただしExecutorはtraitになっているので、実装の差し替えが考慮されている?(外部からcustom executorを差し込めるかは不明)
    - なんかそれっぽいissueはある(https://github.com/hyperium/hyper/issues/1854)
    - Executor traitはtokio_executorのものなのでtokioからは逃れられないのだ...
    - wakerどっかで呼んでるはずだけどどこ?

    - hyper serverメモ

    - Serverは内部的にspawn_allというものを格納したServer構造体を返している(https://github.com/hyperium/hyper/blob/master/src/server/mod.rs)
    - ServerはFutureをimplしており、これをtokioに渡すと非同期サーバーが立ち上がる。pollではspawn_allに対してpoll_watchを実行している
    - poll_watch内部でpoll_next_を読んでいる。ここでリクエストの受け入れを行なっている? https://github.com/hyperium/hyper/blob/master/src/server/conn.rs#L659 (imcoming(Accept traitを要求).poll_acceptを実行しているので)
    - Accept trait https://github.com/hyperium/hyper/blob/master/src/server/accept.rs#L18
    - Serveでpoll_next_を実行し,Connecting構造体を返している
    - NewSvcTask https://github.com/hyperium/hyper/blob/master/src/server/conn.rs#L852 (Futureをimplしている)

    - poll_watchでSpwanAll内部のServeのpoll_next_を実行。poll_next_内部でpoll_acceptを実行。Connecting structが返ってくる。poll_watchでserveのpoll_next_から返ってきたconnecting構造体をNewSvcTask::newに渡して、serveのexec(HTTP構造体)経由execute_new_svcを実行。
    - execute_new_svc内部でtokio::task::spawnを実行している。 https://github.com/hyperium/hyper/blob/master/src/common/exec.rs

    - hyper client メモ

    - get requestの場合
    - ClientのrequestがResponseFutureを返している(Future traitをimplしている)。
    -