1 /*
2  * Copyright (c) 2001 by Matt Welsh and The Regents of the University of
3  * California. All rights reserved.
4  *
5  * Permission to use, copy, modify, and distribute this software and its
6  * documentation for any purpose, without fee, and without written agreement is
7  * hereby granted, provided that the above copyright notice and the following
8  * two paragraphs appear in all copies of this software.
9  *
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 
readInit(SelectSourceIF read_selsource, SinkIF compQ, int readClogTries)57   protected abstract void readInit(SelectSourceIF read_selsource, SinkIF compQ, int readClogTries);
doRead()58   protected abstract void doRead();
addWriteRequest(aSocketRequest req, SourceIF write_selsource)59   protected abstract boolean addWriteRequest(aSocketRequest req, SourceIF write_selsource);
tryWrite()60   protected abstract boolean tryWrite() throws SinkClosedException;
writeMaskEnable()61   protected abstract void writeMaskEnable();
writeMaskDisable()62   protected abstract void writeMaskDisable();
close(SinkIF closeEventQueue)63   protected abstract void close(SinkIF closeEventQueue);
getSocket()64   protected abstract DatagramSocket getSocket();
connect(InetAddress addr, int port)65   protected abstract void connect(InetAddress addr, int port);
66 
initWrite(AUdpWriteRequest req)67   void initWrite(AUdpWriteRequest req) {
68     this.cur_write_req = req;
69     this.cur_write_buf = req.buf;
70   }
71 
writeReset()72   void writeReset() {
73     this.cur_write_req = null;
74     this.outstanding_writes--;
75   }
76 
isClosed()77   boolean isClosed() {
78     return closed;
79   }
80 
81 
82 }
83 
84