Exemplo n.º 1
0
// Lua: net.createServer(type, timeout)
int net_createServer( lua_State *L ) {
  int type, timeout;

  type = luaL_optlong(L, 1, TYPE_TCP);
  timeout = luaL_optlong(L, 2, 30);

  if (type == TYPE_UDP) {
    platform_print_deprecation_note("net.createServer with net.UDP type", "in next version");
    return net_createUDPSocket( L );
  }
  if (type != TYPE_TCP) return luaL_error(L, "invalid type");

  lnet_userdata *u = net_create(L, TYPE_TCP_SERVER);
  u->server.timeout = timeout;
  return 1;
}
Exemplo n.º 2
0
void net_createSockets(struct node *n)
{
    GInetAddress *addr = n->netadr;
    gchar *tmp = g_inet_address_to_string(addr);
    syslog(LOG_DEBUG,"net_createSockets: Creating sockets on ip: %s\n",tmp);
    g_free(tmp);

    guint i;
    for(i=0; i<sizeof(n->classes); i++){
        if( n->classes[i] != 0 ){
            if( !(net_createUDPSocket(n, i) &&
                  net_createTCPSocket(n, i)) )
                    return;
        }
    }

    syslog(LOG_DEBUG,"net_createSockets: Creating tcp management socket listener on port 2324\n");
    GError * err = NULL;
    GSocketAddress * samgt = g_inet_socket_address_new(addr,2324);
    GSocketService *gss = g_socket_service_new();

    if( g_socket_listener_add_address(G_SOCKET_LISTENER(gss), samgt,
        G_SOCKET_TYPE_STREAM, G_SOCKET_PROTOCOL_TCP, NULL, NULL, &err)
            == FALSE ){
        syslog(LOG_WARNING, "net_createSockets: Error while creating socket listener: %s\n", err->message);
        g_error_free(err);
        g_object_unref(gss);
        return;
    }
    n->mgtsocket.n = n;
    n->mgtsocket.socketservice = gss;
    n->mgtsocket.socketaddress = samgt;
    g_signal_connect(gss, "incoming", G_CALLBACK(tcp_listener),
                                        &(n->mgtsocket));
    g_socket_service_start(gss);

    syslog(LOG_DEBUG,"net_createSockets: activating network for this node\n");
   
    avahi_registerServices(n);
    n->netup = TRUE;
}
Exemplo n.º 3
0
// Lua: net.createConnection(type, secure)
int net_createConnection( lua_State *L ) {
  int type, secure;

  type = luaL_optlong(L, 1, TYPE_TCP);
  secure = luaL_optlong(L, 2, 0);

  if (type == TYPE_UDP) {
    platform_print_deprecation_note("net.createConnection with net.UDP type", "in next version");
    return net_createUDPSocket( L );
  }
  if (type != TYPE_TCP) return luaL_error(L, "invalid type");
  if (secure) {
    platform_print_deprecation_note("net.createConnection with secure flag", "in next version");
#ifdef TLS_MODULE_PRESENT
    return tls_socket_create( L );
#else
    return luaL_error(L, "secure connections not enabled");
#endif
  }
  net_create(L, TYPE_TCP_CLIENT);
  return 1;
}