예제 #1
0
파일: client.go 프로젝트: stefanha/bouncin
// newClient returns a new client for a given network connection.
func newClient(conn net.Conn, network *Network) *client {
	var c *client

	recvFunc := func(msg *irc.Message) {
		runloop.CallLater(func() { c.recvFunc(msg) })
	}
	errorFunc := func(err os.Error) {
		runloop.CallLater(func() { c.errorFunc(err) })
	}

	c = &client{conn: irc.NewConn(conn, recvFunc, errorFunc), network: network}
	return c
}
예제 #2
0
파일: server.go 프로젝트: stefanha/bouncin
// newServer returns a new server for a given network connection.
func newServer(conn net.Conn, network *Network) *server {
	var s *server

	if conn == nil {
		return nil
	}

	recvFunc := func(msg *irc.Message) {
		runloop.CallLater(func() { s.recvFunc(msg) })
	}
	errorFunc := func(err os.Error) {
		runloop.CallLater(func() { s.errorFunc(err) })
	}

	s = &server{irc.NewConn(conn, recvFunc, errorFunc), network}
	s.conn.Send(&irc.Message{Command: "NICK", Params: []string{"bouncin"}})
	s.conn.Send(&irc.Message{Command: "USER", Params: []string{"bouncin", "0", "*", "Bouncin test"}})
	return s
}
예제 #3
0
파일: network.go 프로젝트: stefanha/bouncin
func newNetwork(name string, serverConn net.Conn, listen net.Listener) *Network {
	var network *Network

	accept := func(conn net.Conn) {
		runloop.CallLater(func() {
			network.addClient(conn)
		})
	}

	error := func(err os.Error) {
		// TODO listener failed
	}

	l := newListenConn(listen, accept, error)
	network = &Network{name: name, clients: list.New(), listen: l}
	network.server = newServer(serverConn, network)
	return network
}