allow multiple UDP incoming packets in freedom

pull/82/head
Darien Raymond 9 years ago
parent d3ff2b3698
commit 3b1f92b7e8

@ -16,7 +16,7 @@ type TimeOutReader struct {
worker io.Reader worker io.Reader
} }
func NewTimeOutReader(timeout int, connection net.Conn) *TimeOutReader { func NewTimeOutReader(timeout int /* seconds */, connection net.Conn) *TimeOutReader {
reader := &TimeOutReader{ reader := &TimeOutReader{
connection: connection, connection: connection,
timeout: -100, timeout: -100,

@ -1,6 +1,7 @@
package freedom package freedom
import ( import (
"io"
"net" "net"
"sync" "sync"
@ -58,21 +59,14 @@ func (this *FreedomConnection) Dispatch(firstPacket v2net.Packet, ray ray.Outbou
defer readMutex.Unlock() defer readMutex.Unlock()
defer close(output) defer close(output)
response, err := v2io.ReadFrom(conn, nil) var reader io.Reader
log.Info("Freedom receives ", response.Len(), " bytes from ", conn.RemoteAddr()) reader = conn
if response.Len() > 0 {
output <- response
} else {
response.Release()
}
if err != nil {
return
}
if firstPacket.Destination().IsUDP() { if firstPacket.Destination().IsUDP() {
return reader = v2net.NewTimeOutReader(4 /* seconds */, conn)
} }
v2io.RawReaderToChan(output, conn) v2io.RawReaderToChan(output, reader)
}() }()
writeMutex.Lock() writeMutex.Lock()

Loading…
Cancel
Save