01: /*
02: * HttpSocket.java
03: *
04: * Brazil project web application Framework,
05: * export version: 1.1
06: * Copyright (c) 1999 Sun Microsystems, Inc.
07: *
08: * Sun Public License Notice
09: *
10: * The contents of this file are subject to the Sun Public License Version
11: * 1.0 (the "License"). You may not use this file except in compliance with
12: * the License. A copy of the License is included as the file "license.terms",
13: * and also available at http://www.sun.com/
14: *
15: * The Original Code is from:
16: * Brazil project web application Framework release 1.1.
17: * The Initial Developer of the Original Code is: cstevens.
18: * Portions created by cstevens are Copyright (C) Sun Microsystems, Inc.
19: * All Rights Reserved.
20: *
21: * Contributor(s): cstevens, suhler.
22: *
23: * Version: 1.5
24: * Created by cstevens on 99/09/15
25: * Last modified by cstevens on 99/10/14 14:16:55
26: */
27:
28: package sunlabs.brazil.util.http;
29:
30: import java.io.BufferedInputStream;
31: import java.io.BufferedOutputStream;
32: import java.io.IOException;
33: import java.io.InputStream;
34: import java.io.OutputStream;
35: import java.net.Socket;
36: import java.net.UnknownHostException;
37: import sunlabs.brazil.util.SocketFactory;
38:
39: /**
40: * This class is used as the bag of information kept about a open, idle
41: * socket. It is not meant to be used externally by anyone except someone
42: * writing a new implementation of an <code>HttpSocketPool</code> for
43: * the <code>HttpRequest</code> object.
44: * <p>
45: * This class should not be visible at this scope. It is only here until
46: * a better place for it is found.
47: */
48: public class HttpSocket {
49: public String host;
50: public int port;
51:
52: public boolean firstTime = true;
53: public long lastUsed;
54: public int timesUsed = 1;
55:
56: public Socket sock;
57: public InputStream in;
58: public OutputStream out;
59:
60: private static int count = 0;
61: private int serial;
62:
63: public HttpSocket(String host, int port) throws IOException,
64: UnknownHostException {
65: this .host = host;
66: this .port = port;
67:
68: SocketFactory socketFactory = HttpRequest.socketFactory;
69: if (socketFactory == null) {
70: socketFactory = SocketFactory.defaultFactory;
71: }
72:
73: sock = socketFactory.newSocket(host, port);
74: in = new BufferedInputStream(sock.getInputStream());
75: out = new BufferedOutputStream(sock.getOutputStream());
76:
77: serial = count++;
78: }
79:
80: void close() {
81: in = null;
82: out = null;
83:
84: if (sock != null) {
85: try {
86: sock.close();
87: } catch (IOException e) {
88: }
89: }
90:
91: sock = null;
92: }
93:
94: public String toString() {
95: return host + ":" + port + "-" + serial + "-" + timesUsed;
96: }
97: }
|