coder / coder/websocket

How to extract a fd using this library?

オープン
#331 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
enhancement
主要言語
Go
スター
5.5k
フォーク
372
PR マージ指標
30日以内にマージされた PR はありません

説明

I am trying to keep track of some user state in my application and I would like to get an integer fd of the connection so I can hash and keep track of it in my data structure. I tried below and I get the following error

```
reflect: call of reflect.Value.FieldByName on zero Value
````
having this functionality in the connection struct would really help.

```
netConn := websocket.NetConn(context.Background(), conn, websocket.MessageText)
```

```
func GetFdFromConn(conn net.Conn) int {
tcpConn := reflect.Indirect(reflect.ValueOf(conn)).FieldByName("conn")
fdVal := tcpConn.FieldByName("fd")
pfdVal := reflect.Indirect(fdVal).FieldByName("pfd")
return int(pfdVal.FieldByName("Sysfd").Int())
}
```

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。