RCSID("$Header$");
-extern char *krb_get_lrealm(char *, int);
-
client *cur_client;
char *whoami;
/*
* Establish template connection.
*/
- if (!(listener = mr_listen(port)))
+ listener = mr_listen(port);
+ if (listener == -1)
{
com_err(whoami, status, "trying to create listening connection");
exit(1);
/* Handle any new connections */
if (FD_ISSET(listener, &readfds))
{
- int newconn;
+ int newconn, addrlen = sizeof(struct sockaddr_in);
struct sockaddr_in addr;
client *cp;
- newconn = mr_accept(listener, &addr);
+ newconn = accept(listener, (struct sockaddr *)&addr, &addrlen);
if (newconn == -1)
com_err(whoami, errno, "accepting new connection");
else if (newconn > 0)
cp->tuplessize = 1;
cp->tuples = xmalloc(sizeof(mr_params));
memset(cp->tuples, 0, sizeof(mr_params));
+ cp->state = CL_ACCEPTING;
+ cp->version = 2;
cur_client = cp;
com_err(whoami, 0,
if (!clients[i]->ntuples)
{
FD_CLR(clients[i]->con, &xwritefds);
- /* Now that we're done writing we can read again */
FD_SET(clients[i]->con, &xreadfds);
}
clients[i]->last_time_used = now;
if (FD_ISSET(clients[i]->con, &readfds))
{
- client_read(clients[i]);
- if (clients[i]->ntuples)
- FD_SET(clients[i]->con, &xwritefds);
- clients[i]->last_time_used = now;
+ if (clients[i]->state == CL_ACCEPTING)
+ {
+ switch(mr_cont_accept(clients[i]->con,
+ &clients[i]->hsbuf,
+ &clients[i]->hslen))
+ {
+ case -1:
+ break;
+
+ case 0:
+ clients[i]->state = CL_CLOSING;
+ break;
+
+ default:
+ clients[i]->state = CL_ACTIVE;
+ clients[i]->hsbuf = NULL;
+ break;
+ }
+ }
+ else
+ {
+ client_read(clients[i]);
+ if (clients[i]->ntuples)
+ {
+ FD_CLR(clients[i]->con, &xreadfds);
+ FD_SET(clients[i]->con, &xwritefds);
+ }
+ clients[i]->last_time_used = now;
+ }
}
if (clients[i]->last_time_used < tardy)
{
com_err(whoami, 0, "Shutting down connection due to inactivity");
- clients[i]->done = 1;
+ clients[i]->state = CL_CLOSING;
}
- if (clients[i]->done)
+ if (clients[i]->state == CL_CLOSING)
{
client *old;
FD_CLR(clients[i]->con, &xwritefds);
free_rtn_tuples(clients[i]);
free(clients[i]->tuples);
+ free(clients[i]->hsbuf);
old = clients[i];
clients[i] = clients[--nclients];
free(old);
if (pid == inc_pid)
inc_running = 0;
if (!takedown && (WTERMSIG(status) != 0 || WEXITSTATUS(status) != 0))
- com_err(whoami, 0, "%d: child exits with signal %d status %d",
- pid, WTERMSIG(status), WEXITSTATUS(status));
+ {
+ critical_alert("moirad", "%d: child exits with signal %d status %d",
+ pid, WTERMSIG(status), WEXITSTATUS(status));
+ }
}
}