isc_handler.c 1.5 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
/*
** isc_handler.c                 Routines to handle IscSession handlers
**
** Copyright (c) 1992 Peter Eriksson and Per Cederqvist of the
**                    Lysator Academic Computer Association.
**
** history:
** 920211 pen      initial coding
*/

#include <stdio.h>

#include "isc.h"
#include "intern.h"



IscHandler *
isc_copyhandler(IscHandler *hcb)
{
  IscHandler *nhcb;


  ISC_XNEW(nhcb);
  *nhcb = *hcb;

  return nhcb;
}



IscHandler *
isc_newhandler(void)
{
  IscHandler *hcb;


  ISC_XNEW(hcb);
  
  hcb->read = NULL;
  hcb->write = NULL;
  hcb->close = NULL;
  hcb->poll = NULL;
  hcb->accept = NULL;
  hcb->destroy = NULL;
  hcb->parse = NULL;
  
  return hcb;
}



void
isc_freehandler(IscHandler *hcb)
{
  isc_free(hcb);
}



void
isc_pushhandler(IscSession *scb, IscHandler *hcb)
{
  IscHandlerList *ihl;

  
  ISC_XNEW(ihl);
  ihl->hcb = hcb;
  ihl->old = scb->fun;
  ihl->next = scb->handlers;
  
  scb->handlers = ihl;

  if (hcb->read)
    scb->fun.read = ihl;
  if (hcb->write)
    scb->fun.write = ihl;
  if (hcb->close)
    scb->fun.close = ihl;
  if (hcb->poll)
    scb->fun.poll = ihl;
  if (hcb->accept)
    scb->fun.accept = ihl;
  if (hcb->destroy)
    scb->fun.destroy = ihl;
  if (hcb->parse)
    scb->fun.parse = ihl;
}


IscHandler *
isc_pophandler(IscSession *scb)
{
  IscHandlerList *ip;
  IscHandler *hcb;

  
  if (scb->handlers == NULL)
    return NULL;

  ip = scb->handlers;
  scb->handlers = ip->next;
  scb->fun = ip->old;
  hcb = ip->hcb;
    
  isc_free(ip);
  
  return hcb;
}