OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [c/] [src/] [librdbg/] [src/] [servcon.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*
2
 **************************************************************************
3
 *
4
 *  Component:  RDBG
5
 *  Module:     servcon.c
6
 *
7
 *  Synopsis:   Management of RPC client connections.
8
 *
9
 * servcon.c,v 1.3 2002/02/01 17:00:01 joel Exp
10
 *
11
 **************************************************************************
12
 */
13
 
14
#include <sys/errno.h>
15
#include <rdbg/rdbg.h>
16
#include <rdbg/servrpc.h>
17
 
18
    /*
19
     *  ConnCreate - create a new connection entry for a client.
20
     *
21
     *  This function finds an empty entry in the connection array
22
     *  or makes space. It fills in the fields that are passed to it.
23
     *  It does not do any validation on net addresses nor does it
24
     *  start a validation cycle on other clients. This is done by
25
     *  the caller.
26
     */
27
 
28
  int
29
ConnCreate (struct svc_req *rqstp, open_in * in)
30
{
31
  NET_OPAQUE sender;
32
  int idx;
33
  CONN_LIST *clst;
34
 
35
  setErrno (0);
36
 
37
  /*
38
   * Convert to valid Net address
39
   */
40
  if (!TspTranslateRpcAddr (rqstp, &sender)) {
41
    DPRINTF (("ConnCreate: TspTranslateRpcAddr failed\n"));
42
    return -1;
43
  }
44
  if (!TspValidateAddr ((NET_OPAQUE *) in->back_port, &sender)) {
45
    DPRINTF (("ConnCreate: TspValidateAddr failed\n"));
46
    return -1;                  /* errno now setup with error */
47
  }
48
 
49
  /*
50
   * look for an empty connection entry
51
   */
52
  for (idx = 0; idx < conn_list_cnt; idx++) {
53
    if (!conn_list[idx].in_use)
54
      break;                    /* an empty one found */
55
  }
56
 
57
  if (idx >= conn_list_cnt) {   /* no empties, create space */
58
    CONN_LIST *tmp_conn_list = conn_list;
59
 
60
    conn_list_cnt += CONN_LIST_INC;
61
    if (conn_list) {
62
      conn_list = (CONN_LIST *) Realloc (conn_list, /* extend */
63
                                         conn_list_cnt * sizeof (CONN_LIST));
64
    } else {
65
      conn_list = (CONN_LIST *) Malloc (conn_list_cnt * sizeof (CONN_LIST));
66
    }
67
 
68
    if (!conn_list) {           /* unable to get space */
69
      if ((conn_list_cnt -= CONN_LIST_INC)) {
70
        /*
71
         * was realloc, restore space
72
         */
73
        conn_list = tmp_conn_list;
74
      }
75
      return -1;                /* errno set by failed alloc */
76
    }
77
    /*
78
     * clear newly created memory
79
     */
80
    memset (conn_list + idx, 0, CONN_LIST_INC * sizeof (CONN_LIST));
81
  } else {                      /* clear new entry */
82
    memset (conn_list + idx, 0, sizeof (CONN_LIST));
83
  }
84
  clst = conn_list + idx;
85
 
86
  clst->in_use = True;          /* now in use */
87
  clst->sender = sender;
88
  memcpy (&clst->back_port, &in->back_port, sizeof (NET_OPAQUE));
89
  memcpy (&clst->route, &in->destination, sizeof (NET_OPAQUE));
90
  clst->debug_type = (UCHAR) in->debug_type;
91
  clst->flags = in->flags;
92
  strncpy (clst->user_name, in->user_name, NAMEMAX - 1);
93
  clst->user_name[NAMEMAX - 1] = 0;
94
 
95
  return idx;
96
}
97
 
98
    /*
99
     *  ConnDelete - remove connection entry when shutdown.
100
     *
101
     */
102
 
103
  void
104
ConnDelete (int conn, struct svc_req *rqstp, close_control control)
105
{
106
  CONN_LIST *clst = conn_list + conn;
107
  int idx;
108
  Boolean prim;
109
 
110
  if (!clst->in_use)
111
    return;                     /* not active */
112
 
113
  for (idx = 0; idx < pid_list_cnt; idx++) {
114
    PID_LIST *plst = pid_list + idx;
115
 
116
    if (!PIDMAP_TEST (conn, idx))
117
      continue;
118
 
119
    /*
120
     * found a controlled pid
121
     */
122
    prim = (plst->primary_conn == conn) ? True : False;
123
    TgtDetachCon (conn, idx, True);
124
 
125
    /*
126
     * if still running or alive, we use close control on it
127
     */
128
    if (!plst->pid)
129
      continue;                 /* entry gone */
130
 
131
    if (prim && control == CLOSE_KILL) {
132
      /*
133
       * kill off process
134
       */
135
      TgtKillAndDelete (plst, rqstp, True);
136
    } else if (!plst->owners) {
137
      /*
138
       * no owners left
139
       */
140
      if (control == CLOSE_DETACH) {
141
        TgtKillAndDelete (plst, rqstp, False);
142
      }
143
      if (control == CLOSE_DETACH || PROC_TERMINATED (plst)) {
144
        TgtDelete (plst, conn, (control == CLOSE_DETACH) ? BMSG_DETACH : 0);
145
      }
146
    }
147
  }
148
  if (clst->list) {
149
    Free (clst->list);          /* free allocated memory */
150
  }
151
  DPRINTF (("ConnDelete: Connection closed for port %u\n",
152
            HL_W (*((UINT16 *) & clst->back_port.c[2]))));
153
 
154
  clst->in_use = False;         /* free it back */
155
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.