01: /*
02: * Copyright (c) 2001 by Matt Welsh and The Regents of the University of
03: * California. All rights reserved.
04: *
05: * Permission to use, copy, modify, and distribute this software and its
06: * documentation for any purpose, without fee, and without written agreement is
07: * hereby granted, provided that the above copyright notice and the following
08: * two paragraphs appear in all copies of this software.
09: *
10: * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
11: * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
12: * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
13: * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14: *
15: * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
16: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17: * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
18: * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
19: * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
20: *
21: * Author: Matt Welsh <mdw@cs.berkeley.edu>
22: *
23: */
24:
25: package seda.sandStorm.lib.aSocket;
26:
27: import seda.sandStorm.api.*;
28: import seda.sandStorm.core.*;
29:
30: import java.net.*;
31: import java.io.*;
32: import java.util.*;
33:
34: /**
35: * Internal class used to represent state of an active datagram socket.
36: */
37: public abstract class DatagramSockState implements aSocketConst {
38:
39: private static final boolean DEBUG = false;
40:
41: protected AUdpSocket udpsock;
42: protected SinkIF readCompQ;
43: protected QueueElementIF clogged_qel;
44: protected int clogged_numtries;
45: protected int readClogTries, writeClogThreshold, maxPacketSize;
46:
47: protected byte readBuf[];
48: protected boolean closed = false;
49: protected long seqNum = 1;
50: protected AUdpInPacket pkt;
51:
52: protected int outstanding_writes, numEmptyWrites;
53: protected ssLinkedList writeReqList;
54: protected AUdpWriteRequest cur_write_req;
55: protected BufferElement cur_write_buf;
56:
57: protected abstract void readInit(SelectSourceIF read_selsource,
58: SinkIF compQ, int readClogTries);
59:
60: protected abstract void doRead();
61:
62: protected abstract boolean addWriteRequest(aSocketRequest req,
63: SourceIF write_selsource);
64:
65: protected abstract boolean tryWrite() throws SinkClosedException;
66:
67: protected abstract void writeMaskEnable();
68:
69: protected abstract void writeMaskDisable();
70:
71: protected abstract void close(SinkIF closeEventQueue);
72:
73: protected abstract DatagramSocket getSocket();
74:
75: protected abstract void connect(InetAddress addr, int port);
76:
77: void initWrite(AUdpWriteRequest req) {
78: this .cur_write_req = req;
79: this .cur_write_buf = req.buf;
80: }
81:
82: void writeReset() {
83: this .cur_write_req = null;
84: this .outstanding_writes--;
85: }
86:
87: boolean isClosed() {
88: return closed;
89: }
90:
91: }
|