001/* jpvmConnectionServer.java
002 *
003 * The jpvmConnectionServer class implements the thread of control 
004 * in each jpvm program that establishes connections with other
005 * jpvm tasks that want to send data.
006 *
007 * Adam J Ferrari
008 * Sat 05-25-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;
033import jpvm.jpvmConnectionSet;
034import jpvm.jpvmRecvThread;
035import jpvm.jpvmMessageQueue;
036
037public
038class jpvmBarrierServer extends Thread {
039        private ServerSocket            connectionSock;
040        private int                     connectionPort;
041        private jpvmConnectionSet       connectionSet;
042
043        public jpvmBarrierServer(int port) {
044                connectionSock = null;
045                connectionPort = port;
046                try {
047                        connectionSock = new ServerSocket(connectionPort);
048                //      connectionPort = connectionSock.getLocalPort();
049                }
050                catch (IOException ioe) {
051                        ioe.printStackTrace();
052                        jpvmDebug.error("jpvmConnectionServer, i/o exception");
053                }
054        }
055
056        public int getConnectionPort() {
057                return connectionPort;
058        }
059
060        public void run() {
061            while(true) {
062              try {
063
064                Socket newConnSock = connectionSock.accept();
065
066                try{
067                        newConnSock.setTcpNoDelay(true);
068                }
069                catch (NoSuchMethodError er) {
070                }
071
072//              System.out.println("get one connection");
073                jpvmRecvBarrier nw = new jpvmRecvBarrier(newConnSock);
074
075                // Start a thread to recv on this pipe
076                nw.start();
077              }
078              catch (IOException ioe) {
079                        ioe.printStackTrace();
080                        jpvmDebug.error("jpvmConnectionServer, run - " + 
081                                "i/o exception");
082              }
083            }
084        }
085};