001/* jpvmRecvConnection.java
002 *
003 * The jpvmRecvConnection class implements objects that represent
004 * connections to remote jpvm processes from which messages may be
005 * received.
006 *
007 * Adam J Ferrari
008 * Sun 05-26-1996
009 *
010 * Copyright (C) 1996  Adam J Ferrari
011 * 
012 * This library is free software; you can redistribute it and/or
013 * modify it under the terms of the GNU Library General Public
014 * License as published by the Free Software Foundation; either
015 * version 2 of the License, or (at your option) any later version.
016 * 
017 * This library is distributed in the hope that it will be useful,
018 * but WITHOUT ANY WARRANTY; without even the implied warranty of
019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
020 * Library General Public License for more details.
021 * 
022 * You should have received a copy of the GNU Library General Public
023 * License along with this library; if not, write to the
024 * Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
025 * MA 02139, USA.
026 */
027
028package jpvm;
029
030import java.net.*;
031import java.io.*;
032import jpvm.jpvmTaskId;
033
034public
035class jpvmRecvConnection {
036        private InputStream     instrm;
037        public DataInputStream  strm;
038        public jpvmTaskId       tid;
039        
040        public jpvmRecvConnection() {
041                instrm = null;
042                strm = null;
043                tid   = null;
044        }
045
046        public jpvmRecvConnection(Socket sock) {
047                if(sock==null) return;
048                try {
049                        instrm = sock.getInputStream();
050                        instrm = new BufferedInputStream(instrm);
051                        strm = new DataInputStream(instrm);
052                        tid = new jpvmTaskId();
053                        try {
054                                tid.recv(strm);
055                        }
056                        catch (jpvmException jpe) {
057                                strm  = null;
058                                tid   = null;
059                                jpvmDebug.error("jpvmRecvConnection, internal"+
060                                        " error");
061                        }
062                        jpvmDebug.note("jpvmRecvConnection, connect to "
063                                +tid.toString()+" established");
064                }
065                catch (IOException ioe) {
066                        strm  = null;
067                        tid   = null;
068                        jpvmDebug.error("jpvmRecvConnection, i/o exception");
069                }
070                if(strm == null) return;
071        }
072
073        public boolean hasMessagesQueued() {
074                boolean ret = false;
075                if(instrm != null) {
076                        try {
077                          if (instrm.available() > 0)
078                                ret = true;
079                        }
080                        catch (IOException ioe) {
081                                ret = false;
082                                jpvmDebug.error("jpvmRecvConnection, " +
083                                        "hasMessagesQueued - i/o exception");
084                        }
085                }
086                return ret;
087        }
088};