aboutsummaryrefslogtreecommitdiff
path: root/lib/websocket/funcs.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2019-03-11 04:49:03 +0700
committerShulhan <ms@kilabit.info>2019-03-11 04:49:03 +0700
commitb375bcf53418f088c633e8f6fe0d210aca4a6978 (patch)
treedc1ee98a31be7f009f582a7f640a2c4978257603 /lib/websocket/funcs.go
parentaf3d1f29dd7abfb3f900ae9c03b84d0404e76102 (diff)
downloadpakakeh.go-b375bcf53418f088c633e8f6fe0d210aca4a6978.tar.xz
websocket: handle possible half write on Send()
When sending large payload, there is a possibility that a single Write may not send all packet due to buffer or size limit on TCP.
Diffstat (limited to 'lib/websocket/funcs.go')
-rw-r--r--lib/websocket/funcs.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/websocket/funcs.go b/lib/websocket/funcs.go
index a7cb2f93..ce215018 100644
--- a/lib/websocket/funcs.go
+++ b/lib/websocket/funcs.go
@@ -43,9 +43,16 @@ func Recv(fd int) (packet []byte, err error) {
// Send the packet through web socket file descriptor `fd`.
//
func Send(fd int, packet []byte) (err error) {
- _, err = unix.Write(fd, packet)
+ var n int
+ for len(packet) > 0 {
+ n, err = unix.Write(fd, packet)
+ if err != nil {
+ break
+ }
+ packet = packet[n:]
+ }
- return
+ return err
}
//