@@ -40,7 +40,7 @@ type NativeTun struct {
4040 inet4Address [4 ]byte
4141 inet6Address [16 ]byte
4242 routeSet bool
43- writeMsgX bool
43+ sendMsgX bool
4444}
4545
4646type iovecBuffer struct {
@@ -64,8 +64,7 @@ func (b *iovecBuffer) nextIovecs() []unix.Iovec {
6464 }
6565 if b .buffer == nil {
6666 b .buffer = buf .NewSize (b .mtu )
67- b .iovecs [1 ].Base = & b .buffer .FreeBytes ()[0 ]
68- b .iovecs [1 ].SetLen (b .mtu )
67+ b .iovecs [1 ] = b .buffer .Iovec (b .buffer .Cap ())
6968 }
7069 return b .iovecs
7170}
@@ -77,8 +76,7 @@ func (b *iovecBuffer) nextIovecsOutput(buffer *buf.Buffer) []unix.Iovec {
7776 case header .IPv6Version :
7877 b .iovecs [0 ] = packetHeaderVec6
7978 }
80- b .iovecs [1 ].Base = & buffer .Bytes ()[0 ]
81- b .iovecs [1 ].SetLen (buffer .Len ())
79+ b .iovecs [1 ] = buffer .Iovec (buffer .Len ())
8280 return b .iovecs
8381}
8482
@@ -132,7 +130,7 @@ func New(options Options) (Tun, error) {
132130 msgHdrs : make ([]rawfile.MsgHdrX , batchSize ),
133131 msgHdrsOutput : make ([]rawfile.MsgHdrX , batchSize ),
134132 stopFd : common .Must1 (stopfd .New ()),
135- writeMsgX : options .EXP_SendMsgX ,
133+ sendMsgX : options .EXP_SendMsgX ,
136134 }
137135 for i := 0 ; i < batchSize ; i ++ {
138136 nativeTun .iovecs [i ] = newIovecBuffer (int (options .MTU ))
@@ -364,7 +362,7 @@ func (t *NativeTun) BatchRead() ([]*buf.Buffer, error) {
364362}
365363
366364func (t * NativeTun ) BatchWrite (buffers []* buf.Buffer ) error {
367- if ! t .writeMsgX {
365+ if ! t .sendMsgX {
368366 for i , buffer := range buffers {
369367 t .iovecsOutput [i ].nextIovecsOutput (buffer )
370368 }
@@ -381,9 +379,13 @@ func (t *NativeTun) BatchWrite(buffers []*buf.Buffer) error {
381379 t .msgHdrsOutput [i ].Msg .Iov = & iovecs [0 ]
382380 t .msgHdrsOutput [i ].Msg .Iovlen = 2
383381 }
384- _ , errno := rawfile .NonBlockingSendMMsg (t .tunFd , t .msgHdrsOutput [:len (buffers )])
385- if errno != 0 {
386- return errno
382+ var n int
383+ for n != len (buffers ) {
384+ sent , errno := rawfile .NonBlockingSendMMsg (t .tunFd , t .msgHdrsOutput [n :len (buffers )])
385+ if errno != 0 {
386+ return errno
387+ }
388+ n += sent
387389 }
388390 }
389391 return nil
0 commit comments