2022-03-10 09:44:48 +00:00
|
|
|
package utp
|
|
|
|
|
|
|
|
/*
|
|
|
|
#include "utp.h"
|
|
|
|
*/
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"github.com/anacrolix/sync"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Option = C.int
|
|
|
|
|
|
|
|
const (
|
|
|
|
LogNormal Option = C.UTP_LOG_NORMAL
|
|
|
|
LogMtu Option = C.UTP_LOG_MTU
|
|
|
|
LogDebug Option = C.UTP_LOG_DEBUG
|
|
|
|
SendBuffer Option = C.UTP_SNDBUF
|
|
|
|
RecvBuffer Option = C.UTP_RCVBUF
|
|
|
|
TargetDelay Option = C.UTP_TARGET_DELAY
|
|
|
|
|
|
|
|
TimedOut = C.UTP_ETIMEDOUT
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
mu sync.Mutex
|
2024-05-30 08:52:57 +00:00
|
|
|
libContextToSocket = map[*utpContext]*Socket{}
|
2022-03-10 09:44:48 +00:00
|
|
|
)
|
|
|
|
|
2024-05-30 08:52:57 +00:00
|
|
|
func getSocketForLibContext(uc *utpContext) *Socket {
|
2022-03-10 09:44:48 +00:00
|
|
|
return libContextToSocket[uc]
|
|
|
|
}
|
|
|
|
|
|
|
|
func errorForCode(code C.int) error {
|
|
|
|
return errors.New(libErrorCodeNames(code))
|
|
|
|
}
|