isc_master.c 3.44 KB
Newer Older
Per Cederqvist's avatar
Per Cederqvist committed
1
2
3
/*
** isc_master.c                               IscMaster control functions
**
Per Cederqvist's avatar
Per Cederqvist committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
** Copyright (C) 1991-1992, 1998-1999 by Peter Eriksson and
** Per Cederqvist of the Lysator Academic Computer Association.
**
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Library General Public
** License as published by the Free Software Foundation; either
** version 2 of the License, or (at your option) any later version.
**
** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
** Library General Public License for more details.
**
** You should have received a copy of the GNU Library General Public
** License along with this library; if not, write to the Free
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
Per Cederqvist's avatar
Per Cederqvist committed
21
22
23
**
** history:
** 910305 pen      moved to separate file
Per Cederqvist's avatar
Per Cederqvist committed
24
** (See ChangeLog for recent history)
Per Cederqvist's avatar
Per Cederqvist committed
25
26
*/

Per Cederqvist's avatar
Per Cederqvist committed
27
#include <time.h>
Per Cederqvist's avatar
Per Cederqvist committed
28
#include <errno.h>
Per Cederqvist's avatar
Per Cederqvist committed
29
#ifdef HAVE_STDLIB_H
Per Cederqvist's avatar
Per Cederqvist committed
30
#  include <stdlib.h>
Per Cederqvist's avatar
Per Cederqvist committed
31
#endif
Per Cederqvist's avatar
Per Cederqvist committed
32
33
34
#ifdef HAVE_STDDEF_H
#  include <stddef.h>
#endif
35
36
37
38
#ifdef HAVE_STDARG_H
#  include <stdarg.h>
#endif
#include <sys/types.h>
Per Cederqvist's avatar
Per Cederqvist committed
39
#include <sys/file.h>
40
#include <sys/socket.h>
41
42
43
44
#ifndef NULL
#  include <stdio.h>
#endif

45
#include "oop.h"
46
47
#include "adns.h"
#include "oop-adns.h"
48
49

#include "s-string.h"
50
#include "timeval-util.h"
51

Per Cederqvist's avatar
Per Cederqvist committed
52
53
54
55
56
57
58
59
#include "isc.h"
#include "intern.h"



/*
** This routine will initialize the ISC subsystem
*/
60
struct isc_mcb *
61
62
isc_initialize(oop_source *event_source,
	       isc_write_queue_change_cb *write_change_cb)
Per Cederqvist's avatar
Per Cederqvist committed
63
{
64
  struct isc_mcb    * mcb;
65
66
67
68
69
70
71
72
73
74
  oop_adapter_adns  * adns;

  adns = oop_adns_new(event_source,
		      0
		      |adns_if_logpid
		      |adns_if_checkc_entex
		      |adns_if_nosigpipe,
		      stderr);
  if (adns == NULL)
      return NULL;
75

Per Cederqvist's avatar
Per Cederqvist committed
76
  ISC_XNEW(mcb);
77
  ISC_XNEW(mcb->scfg);
Per Cederqvist's avatar
Per Cederqvist committed
78
  mcb->sessions = NULL;
79
  mcb->adns = adns;
Per Cederqvist's avatar
Per Cederqvist committed
80
81
  
  /* Setup default values */
82
83
84
85
86
  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.backlog     = ISC_DEFAULT_MAX_BACKLOG;
  mcb->scfg->fd_relocate     = 0;
87
  mcb->scfg->stale_timeout   = timeval_ctor(3600, 0);
Per Cederqvist's avatar
Per Cederqvist committed
88

89
90
91
92
  /* Default to no byte limit. */
  mcb->scfg->max.queuedsize_bytes = (ISC_DEFAULT_MAX_QUEUED_SIZE
				     * ISC_DEFAULT_MAX_MSG_SIZE);

93
  mcb->event_source = event_source;
94
95
  mcb->write_change_cb = write_change_cb;

Per Cederqvist's avatar
Per Cederqvist committed
96
97
98
99
  return mcb;
}


100
101
102
103
104
105
106
107
void
isc_cfg_fd_relocate(struct isc_mcb *mcb,
		    int fd_relocate)
{
  mcb->scfg->fd_relocate = fd_relocate;
}
  

108
109
void
isc_cfg_stale_timeout(struct isc_mcb *mcb,
110
111
		      struct timeval stale,
		      struct timeval default_idle)
112
{
113
114
  mcb->scfg->stale_timeout = stale;
  mcb->scfg->idle_timeout = default_idle;
115
}
116

117
118
119
120
121
122
123
124
125
126
127
128
129
void
isc_cfg_queue_size(struct isc_mcb *mcb,
		   int max_queue_size_bytes,
		   int max_msg_size,
		   int max_queue_size_msgs,
		   int max_dequeue_msgs)
{
  mcb->scfg->max.msgsize = max_msg_size;
  mcb->scfg->max.queuedsize = max_queue_size_msgs;
  mcb->scfg->max.queuedsize_bytes = max_queue_size_bytes;
  mcb->scfg->max.dequeuelen = max_dequeue_msgs;
}

Per Cederqvist's avatar
Per Cederqvist committed
130
131
132
133
134
135

/*
** Close and destroy all sessions associated with a MCB, then
** destroy the MCB too.
*/
void
136
isc_shutdown(struct isc_mcb  * mcb)
Per Cederqvist's avatar
Per Cederqvist committed
137
138
{
  while (mcb->sessions)
139
    isc_destroy(mcb, &mcb->sessions->scb->pub);
Per Cederqvist's avatar
Per Cederqvist committed
140

141
  oop_adns_delete(mcb->adns);
142
  isc_free(mcb->scfg);
Per Cederqvist's avatar
Per Cederqvist committed
143
144
  isc_free(mcb);
}