Commit 98dfd51c authored by AlexStocks's avatar AlexStocks

delete udp_server

parent d1e123b3
......@@ -66,7 +66,7 @@ func newClient(t EndPointType, opts ...ClientOption) *client {
c.init(opts...)
if t != UNCONNECTED_UDP_CLIENT && c.number <= 0 || c.addr == "" {
if c.number <= 0 || c.addr == "" {
panic(fmt.Sprintf("@connNum:%d, @serverAddr:%s", c.number, c.addr))
}
......@@ -80,20 +80,9 @@ func NewTCPClient(opts ...ClientOption) Client {
return newClient(TCP_CLIENT, opts...)
}
// NewUdpClient function builds a udp client
// NewUdpClient function builds a connected udp client
func NewUDPClient(opts ...ClientOption) Client {
c := newClient(UNCONNECTED_UDP_CLIENT, opts...)
if len(c.addr) != 0 {
if c.number <= 0 {
panic(fmt.Sprintf("getty will build a preconected connection by @serverAddr:%s while @connNum is %d",
c.addr, c.number))
}
c.endPointType = CONNECTED_UDP_CLIENT
}
return c
return newClient(UDP_CLIENT, opts...)
}
// NewWsClient function builds a ws client.
......@@ -121,7 +110,7 @@ func NewWSSClient(opts ...ClientOption) Client {
return c
}
func (c client) Type() EndPointType {
func (c client) EndPointType() EndPointType {
return c.endPointType
}
......@@ -162,14 +151,10 @@ func (c *client) dialUDP() Session {
if c.IsClosed() {
return nil
}
if UNCONNECTED_UDP_CLIENT == c.endPointType {
conn, err = net.ListenUDP("udp", localAddr)
} else {
conn, err = net.DialUDP("udp", localAddr, peerAddr)
if err == nil && conn.LocalAddr().String() == conn.RemoteAddr().String() {
err = errSelfConnect
}
}
if err == nil {
return newUDPSession(conn, c.endPointType)
}
......@@ -292,7 +277,7 @@ func (c *client) dial() Session {
switch c.endPointType {
case TCP_CLIENT:
return c.dialTCP()
case UNCONNECTED_UDP_CLIENT, CONNECTED_UDP_CLIENT:
case UDP_CLIENT:
return c.dialUDP()
case WS_CLIENT:
return c.dialWS()
......@@ -378,9 +363,9 @@ func (c *client) RunEventLoop(newSession NewSessionCallback) {
}
times = 0
c.connect()
if c.endPointType == UNCONNECTED_UDP_CLIENT || c.endPointType == CONNECTED_UDP_CLIENT {
break
}
//if c.endPointType == UDP_CLIENT {
// break
//}
// time.Sleep(c.interval) // build c.number connections asap
}
}()
......
......@@ -387,7 +387,7 @@ func (u *gettyUDPConn) read(p []byte) (int, *net.UDPAddr, error) {
}
}
if u.ss.Type() == CONNECTED_UDP_CLIENT {
if u.ss.EndPointType() == UDP_CLIENT {
length, err = u.conn.Read(p)
} else {
length, addr, err = u.conn.ReadFromUDP(p)
......@@ -418,7 +418,7 @@ func (u *gettyUDPConn) Write(udpCtx interface{}) (int, error) {
if buf, ok = ctx.Pkg.([]byte); !ok {
return 0, fmt.Errorf("illegal @udpCtx.Pkg{%#v} type", udpCtx)
}
if u.ss.Type() == UDP_SERVER || u.ss.Type() == UNCONNECTED_UDP_CLIENT {
if u.ss.EndPointType() == UDP_CLIENT {
peerAddr = ctx.PeerAddr
if peerAddr == nil {
return 0, ErrNullPeerAddr
......
......@@ -17,39 +17,33 @@ import (
type EndPointType int32
const (
CONNECTED_UDP_CLIENT EndPointType = 0
UNCONNECTED_UDP_CLIENT EndPointType = 1
UDP_ENDPOINT EndPointType = 0
UDP_CLIENT EndPointType = 1
TCP_CLIENT EndPointType = 2
WS_CLIENT EndPointType = 3
WSS_CLIENT EndPointType = 4
UDP_SERVER EndPointType = 6
TCP_SERVER EndPointType = 7
WS_SERVER EndPointType = 8
WSS_SERVER EndPointType = 9
)
var EndPointType_name = map[int32]string{
0: "CONNECTED_UDP_CLIENT",
1: "UNCONNECTED_UDP_CLIENT",
0: "UDP_ENDPOINT",
1: "UDP_CLIENT",
2: "TCP_CLIENT",
3: "WS_CLIENT",
4: "WSS_CLIENT",
6: "UDP_SERVER",
7: "TCP_SERVER",
8: "WS_SERVER",
9: "WSS_SERVER",
}
var EndPointType_value = map[string]int32{
"CONNECTED_UDP_CLIENT": 0,
"UNCONNECTED_UDP_CLIENT": 1,
"UDP_ENDPOINT": 0,
"UDP_CLIENT": 1,
"TCP_CLIENT": 2,
"WS_CLIENT": 3,
"WSS_CLIENT": 4,
"UDP_SERVER": 6,
"TCP_SERVER": 7,
"WS_SERVER": 8,
"WSS_SERVER": 9,
......
......@@ -126,7 +126,7 @@ type Session interface {
Stat() string
IsClosed() bool
// get endpoint type
Type() EndPointType
EndPointType() EndPointType
SetMaxMsgLen(int)
SetName(string)
......@@ -157,7 +157,7 @@ type Session interface {
type EndPoint interface {
// get endpoint type
Type() EndPointType
EndPointType() EndPointType
// run event loop and serves client request.
RunEventLoop(newSession NewSessionCallback)
// check the endpoint has been closed
......
......@@ -75,9 +75,9 @@ func NewTCPServer(opts ...ServerOption) Server {
return newServer(TCP_SERVER, opts...)
}
// NewUDPServer builds a unconnected udp server.
func NewUDPPServer(opts ...ServerOption) Server {
return newServer(UDP_SERVER, opts...)
// NewUDPEndPoint builds a unconnected udp server.
func NewUDPPEndPoint(opts ...ServerOption) Server {
return newServer(UDP_ENDPOINT, opts...)
}
// NewWSServer builds a websocket server.
......@@ -97,7 +97,7 @@ func NewWSSServer(opts ...ServerOption) Server {
return s
}
func (s server) Type() EndPointType {
func (s server) EndPointType() EndPointType {
return s.endPointType
}
......@@ -195,7 +195,7 @@ func (s *server) listen() error {
switch s.endPointType {
case TCP_SERVER, WS_SERVER, WSS_SERVER:
return s.listenTCP()
case UDP_SERVER:
case UDP_ENDPOINT:
return s.listenUDP()
}
......@@ -432,7 +432,7 @@ func (s *server) RunEventLoop(newSession NewSessionCallback) {
switch s.endPointType {
case TCP_SERVER:
s.runTcpEventLoop(newSession)
case UDP_SERVER:
case UDP_ENDPOINT:
s.runUDPEventLoop(newSession)
case WS_SERVER:
s.runWSEventLoop(newSession)
......
......@@ -77,7 +77,7 @@ type session struct {
}
func newSession(endPointType EndPointType, conn Connection) *session {
session := &session{
ss := &session{
name: defaultSessionName,
endPointType: endPointType,
maxMsgLen: maxReadBufLen,
......@@ -88,11 +88,11 @@ func newSession(endPointType EndPointType, conn Connection) *session {
attrs: gxcontext.NewValuesContext(nil),
}
session.Connection.setSession(session)
session.SetWriteTimeout(netIOTimeout)
session.SetReadTimeout(netIOTimeout)
ss.Connection.setSession(ss)
ss.SetWriteTimeout(netIOTimeout)
ss.SetReadTimeout(netIOTimeout)
return session
return ss
}
func newTCPSession(conn net.Conn, endPointType EndPointType) Session {
......@@ -150,7 +150,7 @@ func (s *session) Conn() net.Conn {
return nil
}
func (s *session) Type() EndPointType {
func (s *session) EndPointType() EndPointType {
return s.endPointType
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment