isc_master.c 2.36 KB
Newer Older
Per Cederqvist's avatar
Per Cederqvist committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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
/*
** 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>
#include <stdlib.h>
#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;
  
  
  ISC_XNEW(mcb);
  
  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;
	mcfg = &cfg->master;
	
	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;
	}

	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;

	  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);
}