# include <kernel/kernel.h>
# include <kernel/user.h>
# include <trace.h>
# include <type.h>

private object driver;		/* driver object */
private object userd;		/* user manager object */
private string protocol;        /* telnet, tcp or udp */

/*
 * NAME:	create()
 * DESCRIPTION:	initialize port object
 */
static void create()
{
    driver = find_object(DRIVER);
    userd = find_object(USERD);
}

/*
 * NAME:	open_port()
 * DESCRIPTION:	start listening on a port
 */
static 
void open_port(string prot, varargs int port)
{
    rlimits (-1; -1) {
/*	catch {*/
	if (typeof(port)==T_INT && port !=0) {
		::open_port(prot, port);
	    } else {
		::open_port(prot);
	    }
	    protocol = prot;
	    return;
/*	} : {
	    error(::call_trace()[1][TRACE_FIRSTARG][1]);
	    return;
	    }*/
    }
}

object
connection(mixed *tls, string ip, int port)
{
    object conn;

    switch(protocol) {
      case "telnet" : conn = clone_object(TELNET_CONN);
                      break;
      default       : conn = clone_object(BINARY_CONN);
                      break;
    }
    conn->set_port(port);
    return conn;
}

int 
open(mixed *tls,int port)
{
    return FALSE;
}

void
close(mixed *tls, int force)
{
}

