From owner-freebsd-java@FreeBSD.ORG Wed Jun 18 09:18:51 2003 Return-Path: Delivered-To: freebsd-java@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 469A337B401 for ; Wed, 18 Jun 2003 09:18:51 -0700 (PDT) Received: from zogbe.tasam.com (63-165-178-196.uterr.blacksburg.ntc-com.net [63.165.178.196]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4711443F85 for ; Wed, 18 Jun 2003 09:18:50 -0700 (PDT) (envelope-from clash@tasam.com) Received: from frolickingmoose (root@zogbe.tasam.com [10.95.95.5] (may be forged)) by zogbe.tasam.com (8.12.9/8.12.9) with SMTP id h5IGImOe082884 for ; Wed, 18 Jun 2003 12:18:48 -0400 (EDT) Message-ID: <001101c335b5$4ebd3000$19cf000a@frolickingmoose> From: "Joseph Gleason" To: Date: Wed, 18 Jun 2003 11:18:51 -0500 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_000E_01C3358B.656CEEF0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2720.3000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2727.1300 Subject: NIO Selector creation X-BeenThere: freebsd-java@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Porting Java to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Jun 2003 16:18:51 -0000 This is a multi-part message in MIME format. ------=_NextPart_000_000E_01C3358B.656CEEF0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit I am having trouble using NIO under FreeBSD. I am wondering if it is because of something I am doing wrong or a problem with the port. I am using 4.8-STABLE (May 21) and jdk-1.4.1p3_3 I have this line: HTTPSelector = java.nio.channels.spi.SelectorProvider.provider().openSelector(); This works with jdk 1.4.1 under WinXP. Under FreeBSD I get: root@tesla# java cc.glsn.test.HTTPKick fireduck.com /index.html 80 10 100 Exception in thread "main" java.lang.UnsatisfiedLinkError: init at sun.nio.ch.DevPollArrayWrapper.init(Native Method) at sun.nio.ch.DevPollArrayWrapper.(DevPollArrayWrapper.java:59) at sun.nio.ch.DevPollSelectorImpl.(DevPollSelectorImpl.java:54) at sun.nio.ch.DevPollSelectorProvider.openSelector(DevPollSelectorProvider.java :18) at cc.glsn.test.HTTPKick.(HTTPKick.java:63) at cc.glsn.test.HTTPKick.main(HTTPKick.java:38) I am just learning how to use NIO, so I certainly could be doing something wrong. My code is attached if anyone wants to look at it, but I suspect the problem can be replicated by others with just that one line. I swear my code is usally neater than this...I am just messing around to learn NIO. My thanks to anyone who might be able to help me with me problem. --Joe Gleason ------=_NextPart_000_000E_01C3358B.656CEEF0 Content-Type: application/octet-stream; name="HTTPKick.java" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="HTTPKick.java" // $gleason: test/HTTPKick.java,v 1.2 2003/06/18 16:13:00 clash Exp $ package cc.glsn.test; import java.io.PrintStream; import java.io.PrintWriter; import java.nio.ByteBuffer; import java.nio.channels.Selector; import java.nio.channels.SocketChannel; import java.nio.channels.SelectionKey; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.SocketAddress; import java.util.Set; import java.util.Iterator; /** Attempt at learning how to use NIO by creating a HTTP load testing utility. */ class HTTPKick { String Host; String Path; int Port; int Size; int Count; int DoneOK; int DoneBad; Selector HTTPSelector; boolean ConnsOpen; public static void main(String Args[]) throws Exception { HTTPKick HK=3Dnew HTTPKick(Args); } HTTPKick(String Args[]) throws Exception { DoneOK=3D0; DoneBad=3D0; Host=3DArgs[0]; Path=3DArgs[1]; Port=3Dnew Integer(Args[2]).intValue(); Size=3Dnew Integer(Args[3]).intValue(); Count=3Dnew Integer(Args[4]).intValue(); String Request=3Dnew String("GET " + Path + " HTTP/1.1\r\nHost: = " + Host + "\r\nUser-Agent: kick cc.glsn.HTTPKick/0.5\r\nConnection: = close\r\n\r\n"); ConnsOpen=3Dfalse; HTTPSelector =3D = java.nio.channels.spi.SelectorProvider.provider().openSelector(); Connector C=3Dnew Connector(); C.start(); long D=3D200; while ((!ConnsOpen) || (HTTPSelector.keys().size() > 0)) { while (HTTPSelector.select(D) > 0) { Set SelectedKeys=3DHTTPSelector.selectedKeys(); Iterator I=3DSelectedKeys.iterator(); while (I.hasNext()) { SelectionKey SK=3D(SelectionKey)I.next(); I.remove(); SocketChannel Chan=3D(SocketChannel)SK.channel(); HTTPSession HS=3D(HTTPSession)SK.attachment(); //System.out.print(HS.Name); int Ops=3DSK.readyOps(); //System.out.print(" " + Ops); if (Ops >=3DSK.OP_ACCEPT) { //System.out.print(" + ACCEPT" ); Ops=3DOps-SK.OP_ACCEPT; } if (Ops >=3DSK.OP_CONNECT) { //System.out.print(" + CONNECT" ); Ops=3DOps-SK.OP_CONNECT; SK.interestOps(SK.OP_WRITE); try { Chan.finishConnect(); } catch(Exception e) { System.out.println(HS.Name + " Connection = failed"); e.printStackTrace(); DoneBad++; } } if (Ops >=3DSK.OP_WRITE) { //System.out.print(" + WRITE" ); Ops=3DOps-SK.OP_WRITE; ByteBuffer BB=3DByteBuffer.allocate(10000); //ByteBuffer = BB=3DByteBuffer.wrap(Request.getBytes()); BB.put(Request.getBytes(),0,Request.length()); BB.flip(); //System.out.println(" r=3D" + BB.remaining() = +"."); Chan.write(BB); SK.interestOps(SK.OP_READ); //I.remove(); //PrintWriter PS=3Dnew = PrintWriter(Chan.socket().getOutputStream(),true); //String S=3Dnew String("GET = /fireduck/index.html"); //PS.println(S); } if (Ops >=3DSK.OP_READ) { //System.out.print(" + READ" ); Ops=3DOps-SK.OP_READ; //Chan.socket().shutdownOutput(); Chan.read(HS.Read); //System.out.print(SK.interestOps()); //System.out.print(" R=3D" + = HS.Read.remaining()); //System.out.print(" " + = Chan.socket().isConnected()); //System.out.print(" " + = Chan.socket().isInputShutdown()); //System.out.print(" " + = Chan.socket().isOutputShutdown()); //System.out.print(" " + = Chan.isConnectionPending()); //SK.interestOps(SelectionKey.OP_READ + = SelectionKey.OP_CONNECT + SelectionKey.OP_WRITE); if (HS.Read.remaining()=3D=3D0) { Chan.socket().close(); SK.cancel(); System.out.println(HS.Name + " done."); DoneOK++; } } //System.out.println(); } } } System.out.println("Total: " + (DoneOK + DoneBad)); System.out.println("OK: " + DoneOK); System.out.println("BAD: " + DoneBad); } class HTTPSession { HTTPSession() { Read=3DByteBuffer.allocate(Size); } public String Name; ByteBuffer Read; } class Connector extends Thread { Connector() { } public void run() { System.out.println("Connecting"); try { SocketAddress SA=3Dnew InetSocketAddress(Host,Port); for (int i=3D0; i