isc_master.c 2.55 KB
Newer Older
Per Cederqvist's avatar
Per Cederqvist committed
1
2
3
4
5
6
7
8
9
10
11
/*
** isc_master.c                               IscMaster control functions
**
** Copyright (c) 1992 Peter Eriksson and Per Cederqvist of the
**                    Lysator Academic Computer Association.
**
** history:
** 910305 pen      moved to separate file
*/

#include <errno.h>
Per Cederqvist's avatar
Per Cederqvist committed
12
#ifdef HAVE_STDLIB_H
Per Cederqvist's avatar
Per Cederqvist committed
13
#include <stdlib.h>
Per Cederqvist's avatar
Per Cederqvist committed
14
#endif
Per Cederqvist's avatar
Per Cederqvist committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <stddef.h>
#include <sys/file.h>
#include "isc.h"
#include "intern.h"



/*
** This routine will initialize the ISC subsystem
*/
IscMaster *
isc_initialize(IscConfig  * cfg)
{
  IscMaster         * mcb;
  IscMasterConfig   * mcfg;
  IscSessionConfig  * scfg;
31

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
  
  /* Handle user specified defaults */
  if (cfg)
    switch (cfg->version)
    {
      case 0:
        break;
	
      case 1005:
	mcfg = &cfg->master;
	
	switch (mcfg->version)
	{
	  case 0:
	    break;
	    
	  case 1001:
	    if (mcfg->memfn.alloc &&
		mcfg->memfn.realloc &&
		mcfg->memfn.free)
	      isc_setallocfn(mcfg->memfn.alloc,
			     mcfg->memfn.realloc,
			     mcfg->memfn.free);
	    if (mcfg->abortfn)
	      isc_setabortfn(mcfg->abortfn);
	    break;
58

59
60
61
62
63
	  default:
	    errno = EINVAL;
	    return NULL;
	}
	break;
64

65
66
67
68
69
      default:
	errno = EINVAL;
	return NULL;
    }
  
Per Cederqvist's avatar
Per Cederqvist committed
70
  ISC_XNEW(mcb);
71
  
Per Cederqvist's avatar
Per Cederqvist committed
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
  mcb->sessions = NULL;
  
  
  /* Setup default values */
  mcb->scfg.max.msgsize     = ISC_DEFAULT_MAX_MSG_SIZE;
  mcb->scfg.max.queuedsize  = ISC_DEFAULT_MAX_QUEUED_SIZE;
  mcb->scfg.max.dequeuelen  = ISC_DEFAULT_MAX_DEQUEUE_LEN;
  mcb->scfg.max.openretries = ISC_DEFAULT_MAX_OPEN_RETRIES;
  mcb->scfg.max.backlog     = ISC_DEFAULT_MAX_BACKLOG;
  
  /* Handle user specified defaults */
  if (cfg)
    switch (cfg->version)
    {
      case 1005:
        scfg = &cfg->session;
	
	switch (scfg->version)
	{
	  case 0:
	    break;
	    
	  case 1001:
	    if (scfg->max.msgsize >= 0)
	      mcb->scfg.max.msgsize = scfg->max.msgsize;
	    if (scfg->max.queuedsize >= 0)
	      mcb->scfg.max.queuedsize = scfg->max.queuedsize;
	    if (scfg->max.dequeuelen >= 0)
	      mcb->scfg.max.dequeuelen = scfg->max.dequeuelen;
	    if (scfg->max.openretries >= 0)
	      mcb->scfg.max.openretries = scfg->max.openretries;
	    if (scfg->max.backlog >= 0)
	      mcb->scfg.max.backlog = scfg->max.backlog;
	    break;

	  default:
	    isc_free(mcb);
	    errno = EINVAL;
	    return NULL;
	}

	break;
	
      default:
	isc_free(mcb);
	errno = EINVAL;
	return NULL;
    }
  
  return mcb;
}



/*
** Close and destroy all sessions associated with a MCB, then
** destroy the MCB too.
*/
void
isc_shutdown(IscMaster  * mcb)
{
  while (mcb->sessions)
    isc_destroy(mcb, mcb->sessions->scb);

  isc_free(mcb);
}