Ejemplo n.º 1
0
Archivo: xsm.c Proyecto: aosm/X11
static void
NewConnectionXtProc(XtPointer client_data, int *source, XtInputId *id)
{
    IceConn 	ice_conn;
    char	*connstr;
    IceAcceptStatus status;

    if (shutdownInProgress)
    {
	/*
	 * Don't accept new connections if we are in the middle
	 * of a shutdown.
	 */

	return;
    }

    ice_conn = IceAcceptConnection((IceListenObj) client_data, &status);
    if (! ice_conn) {
	if (verbose)
	    printf ("IceAcceptConnection failed\n");
    } else {
	IceConnectStatus cstatus;

	while ((cstatus = IceConnectionStatus (ice_conn))==IceConnectPending) {
	    XtAppProcessEvent (appContext, XtIMAll);
	}

	if (cstatus == IceConnectAccepted) {
	    if (verbose) {
		printf ("ICE Connection opened by client, IceConn fd = %d, ",
			IceConnectionNumber (ice_conn));
		connstr = IceConnectionString (ice_conn);
		printf ("Accept at networkId %s\n", connstr);
		free (connstr);
		printf ("\n");
	    }
	} else {
	    if (verbose)
	    {
		if (cstatus == IceConnectIOError)
		    printf ("IO error opening ICE Connection!\n");
		else
		    printf ("ICE Connection rejected!\n");
	    }

	    IceCloseConnection (ice_conn);
	}
    }
}
Ejemplo n.º 2
0
static gboolean
ice_connection_accept (GIOChannel  *channel,
                       GIOCondition condition,
                       gpointer     watch_data)
{
  IceConnectStatus cstatus;
  IceAcceptStatus  astatus;
  IceListenObj     ice_listener = (IceListenObj) watch_data;
  IceConn          ice_conn;

  ice_conn = IceAcceptConnection (ice_listener, &astatus);

  if (astatus != IceAcceptSuccess)
    {
      g_warning ("Failed to accept ICE connection on listener %p",
                 (gpointer) ice_listener);
    }
  else
    {
      /* Wait for the connection to leave pending state */
      do
        {
          IceProcessMessages (ice_conn, NULL, NULL);
        }
      while ((cstatus = IceConnectionStatus (ice_conn)) == IceConnectPending);

      if (cstatus != IceConnectAccepted)
        {
          if (cstatus == IceConnectIOError)
            {
              g_warning ("I/O error opening ICE connection %p", (gpointer) ice_conn);
            }
          else
            {
              g_warning ("ICE connection %p rejected", (gpointer) ice_conn);
            }

          IceSetShutdownNegotiation (ice_conn, False);
          IceCloseConnection (ice_conn);
        }
    }

  return TRUE;
}
Ejemplo n.º 3
0
void KSMServer::newConnection( int /*socket*/ )
{
    IceAcceptStatus status;
    IceConn iceConn = IceAcceptConnection( ((KSMListener*)sender())->listenObj, &status);
    if( iceConn == NULL )
        return;
    IceSetShutdownNegotiation( iceConn, False );
    IceConnectStatus cstatus;
    while ((cstatus = IceConnectionStatus (iceConn))==IceConnectPending) {
        (void) IceProcessMessages( iceConn, 0, 0 );
    }

    if (cstatus != IceConnectAccepted) {
        if (cstatus == IceConnectIOError)
            kDebug( 1218 ) << "IO error opening ICE Connection!";
        else
            kDebug( 1218 ) << "ICE Connection rejected!";
        (void )IceCloseConnection (iceConn);
        return;
    }

    // don't leak the fd
    fcntl( IceConnectionNumber(iceConn), F_SETFD, FD_CLOEXEC );
}
static void
ProcessNewPMConnection (
    int				* nfds,
    fd_set			* rinit,
    struct config		* config_info,
    IceListenObj		** listen_objects,
    int				listen_fd)

{
    IceConn			new_ice_conn;
    IceAcceptStatus  		accept_status;
    int				temp_sock_fd;
    IceListenObj *		temp_obj;
    struct timeval		time_val;
    struct timezone		time_zone;
    struct sockaddr_in		temp_sockaddr_in;
    struct sockaddr_in		server_sockaddr_in;
    int				retval;
    int				addrlen = sizeof(temp_sockaddr_in);
    int				rule_number;
    int				pm_idx;

    /*
     * Only continue if there is room for another PM connection.
     */
    for (pm_idx = 0; pm_idx < config_info->num_pm_conns; pm_idx++)
    {
      if (!pm_conn_array[pm_idx])
        break;
    }
    if (pm_idx >= config_info->num_pm_conns)
    {
      (void) fprintf (stderr,
	             "Maximum number of PM connections has been reached (%d)\n",
		     config_info->num_pm_conns);

      /*
       * Must accept and then close this connection or the PM will
       * continue to poll.
       */
      temp_obj = *listen_objects;
      new_ice_conn = IceAcceptConnection(temp_obj[listen_fd], &accept_status);
      if (new_ice_conn)
        IceCloseConnection(new_ice_conn);

      return;
    }

    /*
     * accept the connection if you can, use pm_listen_array
     * index to index into ICE listen_object list (this is because the
     * listen_objects list must correspond to the pm_listen_array)
     */
    temp_obj = *listen_objects;
    new_ice_conn = IceAcceptConnection(temp_obj[listen_fd], &accept_status);
    if (!new_ice_conn)
    {
        static int	been_here;

        /*
         * ICE initialization (bug?) makes this happen the
         * first time readables is hit.
         */
        if (!been_here)
            been_here++;
        else
           (void) fprintf(stderr, "IceAcceptConnection failed (%d)\n",
	  	          accept_status);
       return;
    }

    /*
     * extract the fd from this new connection; remember, the fd of
     * the listen socket is *not* the fd of the actual connection!
     */
    temp_sock_fd = IceConnectionNumber(new_ice_conn);

    /*
     * before we get any further, do a config check on the new ICE
     * connection; start by using getpeername() to get endpoint info
     */
    retval = getpeername(temp_sock_fd,
			 (struct sockaddr*)&temp_sockaddr_in,
			 (void *)&addrlen);
    if (retval)
    {
        IceCloseConnection(new_ice_conn);
        (void) fprintf(stderr, "getpeername call failed\n");
	return;
    }

    assert(temp_sockaddr_in.sin_family == AF_INET);

    /*
     * Do a configuration check.  NOTE:  we're not doing anything
     * with the server_sockaddr_in argument
     */
    if ((doConfigCheck(&temp_sockaddr_in,
		       &server_sockaddr_in,
		       config_info,
		       PMGR,
		       &rule_number)) == FAILURE)
    {
        /*
         * close the PM connection
         *
         */
        (void) fprintf(stderr, "PM failed config check\n");
        IceCloseConnection(new_ice_conn);
        return;
    }

    /*
     * you've started the connection process; allocate a buffer
     * for this connection, then continue processing other fd's without
     * blocking while waiting to read the coming PM data; [NOTE:
     * we use the fd of the connection socket as index into the
     * pm_conn_array; this saves us much troublesome linked-list
     * management!]
     */
    if ((pm_conn_array[pm_idx] = malloc(sizeof(struct pm_conn_buf))) == NULL)
    {
        (void) fprintf (stderr, "malloc - PM connection object\n");
        return;
    }

    /*
     * save the ICEconn struct for future status checks; also
     * the fd (although you could extract it from the ICEconn
     * each time you need it, but that's a pain)
     */
    pm_conn_array[pm_idx]->fd = temp_sock_fd;
    pm_conn_array[pm_idx]->ice_conn = new_ice_conn;

    /*
     * Set the readables select() to listen for a readable on this
     * fd; remember, we're not interested in pm writables, since
     * all the negotiation is handled inside this routine; adjust
     * the nfds (must do that every time we get a new socket to
     * select() on), and then continue processing current selections
     */
    FD_SET(temp_sock_fd, rinit);
    *nfds = max(*nfds, temp_sock_fd + 1);

    /*
     * this is where we initialize the current time and timeout on this
     * pm_connection object
     */
    (void) gettimeofday(&time_val, &time_zone);
    pm_conn_array[pm_idx]->creation_time = time_val.tv_sec;
    pm_conn_array[pm_idx]->time_to_close = config_info->pm_data_timeout;
}