coder / coder/websocket

How to extract a fd using this library?

Aperta
#331 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
enhancement
Lingua principale
Go
Stelle
5.5k
Fork
372
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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())
}
```

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.