listen.c revision 1ae0874509b6811fdde1dfd46f0d93fd09867a3f
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Each group has a listen thread. It is created at the time
* of a group creation and destroyed when a group does not have
* any console associated with it.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <thread.h>
#include <assert.h>
#include <signal.h>
#include <ctype.h>
#include <syslog.h>
#include "vntsd.h"
/*
* check the state of listen thread. exit if there is an fatal error
* or the group is removed.
*/
static void
{
char err_msg[VNTSD_LINE_LEN];
"Group:%s TCP port %lld status %x",
switch (status) {
case VNTSD_SUCCESS:
return;
case VNTSD_STATUS_INTR:
/* close listen socket */
/* let group know */
/* exit thread */
thr_exit(0);
break;
case VNTSD_STATUS_ACCEPT_ERR:
return;
case VNTSD_STATUS_NO_CONS:
default:
/* fatal, exit thread */
thr_exit(0);
break;
}
}
/* allocate and initialize listening socket. */
static int
{
struct sockaddr_in addr;
int on;
/* allocate a socket */
if (*sockfd < 0) {
return (VNTSD_STATUS_INTR);
}
return (VNTSD_ERR_LISTEN_SOCKET);
}
#ifdef DEBUG
/* set reuse local socket address */
on = 1;
return (VNTSD_ERR_LISTEN_OPTS);
}
#endif
/* bind socket */
return (VNTSD_STATUS_INTR);
}
return (VNTSD_ERR_LISTEN_BIND);
}
return (VNTSD_STATUS_INTR);
}
return (VNTSD_ERR_LISTEN_BIND);
}
return (VNTSD_SUCCESS);
}
/* ceate console selection thread */
static int
{
int rv;
/* allocate a new client */
return (VNTSD_ERR_NO_MEM);
}
/* initialize the client */
/* append client to group */
!= VNTSD_SUCCESS) {
return (rv);
}
/* parameters for console thread */
/* create console selection thread */
return (VNTSD_ERR_CREATE_CONS_THR);
}
return (VNTSD_SUCCESS);
}
/* listen thread */
void *
{
int newsockfd;
struct sockaddr_in cli_addr;
int rv;
int num_cons;
/* initialize listen socket */
for (; ; ) {
/* listen to the socket */
&clilen);
if (newsockfd <= 0) {
} else {
}
continue;
}
if (num_cons == 0) {
}
/* a connection is established */
if (rv != VNTSD_SUCCESS) {
}
if (rv != VNTSD_SUCCESS) {
}
}
/*NOTREACHED*/
return (NULL);
}