Example #1
0
// 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
}
Example #2
0
// 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
}
Example #3
0
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
}