coder / coder/websocket

How to extract a fd using this library?

Đang mở
#331 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
enhancement
Ngôn ngữ chính
Go
Star
5.5k
Fork
372
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.