From owner-freebsd-java@FreeBSD.ORG Tue May 29 10:40:41 2012 Return-Path: Delivered-To: freebsd-java@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 592A2106564A for ; Tue, 29 May 2012 10:40:41 +0000 (UTC) (envelope-from Kustaa.Nyholm@planmeca.com) Received: from fsmsg.planmeca.com (fsmsg.planmeca.com [193.94.173.206]) by mx1.freebsd.org (Postfix) with ESMTP id C08868FC12 for ; Tue, 29 May 2012 10:40:40 +0000 (UTC) Received: from srvfihkiexh01.pmgroup.local ([172.26.0.107]) by fsmsg.planmeca.com (8.14.5/8.14.5) with ESMTP id q4TAedTo000932 for ; Tue, 29 May 2012 13:40:39 +0300 Received: from SRVFIHKIEXB01.pmgroup.local ([172.26.0.201]) by srvfihkiexh01.pmgroup.local ([172.26.0.107]) with mapi; Tue, 29 May 2012 13:40:38 +0300 From: Kustaa Nyholm To: "freebsd-java@freebsd.org" Date: Tue, 29 May 2012 13:40:36 +0300 Thread-Topic: tcgetattr hangs Thread-Index: Ac09h3xekCYHHK4aRfyv6ViR+Dr+Tw== Message-ID: Accept-Language: en-US, fi-FI Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: user-agent: Microsoft-MacOutlook/14.0.0.100825 acceptlanguage: en-US, fi-FI Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.6.7580, 1.0.260, 0.0.0000 definitions=2012-05-29_03:2012-05-21, 2012-05-29, 1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 ipscore=0 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=7.0.1-1112030000 definitions=main-1205290068 Subject: tcgetattr hangs X-BeenThere: freebsd-java@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting Java to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 May 2012 10:40:41 -0000 Hi, this maybe wrong list but it was suggested I try my luck here. MY feeling is that this NOT a Java issue per se but here goes. I'm the developer of PureJavaComm (PJC) , a pure Java serial port access library that runs on Mac OS X, Linux, Windows and soon I hope on FreeBSD. I'm co-operating with someone to port the library to FreeBSD but we have run into mysterious problem that has defeated all our debugging efforts. PJC can be found at: https://github.com/nyholku/purejavacomm Some background. PJC uses JNA which is a library to access C-code APIs from Java by writing Java classes that JNA automatically turns in to standard C calls. The C functions we are using are very simple and few, here is the complete list to put you into the picture (btw, this is Java): int errno(); int fcntl(int fd, int cmd, int arg); int cfgetispeed(Termios termios); int cfgetospeed(Termios termios); int setspeed(int fd, int speed); int cfsetispeed(Termios termios, int speed); int cfsetospeed(Termios termios, int speed) int tcflush(int fd, int b); int tcdrain(int fd); void cfmakeraw(Termios termios); int tcgetattr(int fd, Termios termios); int tcsetattr(int fd, int cmd, Termios termios); int tcsendbreak(int fd, int duration); int open(String s, int t); int close(int fd); int write(int fd, byte[] buffer, int len); int read(int fd, byte[] buffer, int len); int ioctl(int fd, int cmd, int[] data); int select(int n, FDSet read, FDSet write, FDSet error, TimeVal timeout); So far we have been able to run PJC testsuite in FreeBSD 32 bit Intel with no problems. Now however, on FreeBSD 64 bit AMD our test set hangs in a call to tcgetattr() in the third test case in our test suite. The first test opens a port and wiggles some control lines, then closes the port. The second test sends and receives a some hundreds of messages using a background thread and select(). This is the test that is causing problem further down the line. After this test the next test (regardless what it is) hangs in a call to tcgetattr() after successfully opening the port. So how can tcgetattr() hang??? I found one reference to a similar problem but no solution: http://freebsd.1045724.n5.nabble.com/Re-cups-bugs-tcgetattr-causes-lockup-i n-USB-backend-on-FreeBSD6-STABLE-td3950285.html Here is a piece of our debug log that shows the calls from Java to the native API showing the end of the successful Test2 and the hang at the beginning of Test3: log: > select(9,[8],[],[],jtermios.TimeVal@6f507fb2) .................................. OK average speed log: < select(9,[],[],[],jtermios.TimeVal@6f507fb2) =3D> 0 log: > select(9,[8],[],[],jtermios.TimeVal@6f507fb2) 18241 b/sec at baud rate 19200 log: > fcntl(8, 3, 0) log: < fcntl(8, 3, 0) =3D> 2 log: > fcntl(8, 4, 6) log: < fcntl(8, 4, 6) =3D> 0 log: > close(8) log: < close(8) =3D> 0 Test3 - transmit all characters log: < select(9,[8],[],[],jtermios.TimeVal@6f507fb2) =3D> -1 log: > open('cuau0',00008006) log: < open('cuau0',00008006) =3D> 8 log: > close(8) log: < close(8) =3D> 0 log: > open('cuau0',00008006) log: < open('cuau0',00008006) =3D> 8 log: > fcntl(8, 3, 0) log: < fcntl(8, 3, 0) =3D> 6 log: > fcntl(8, 4, 2) log: < fcntl(8, 4, 2) =3D> 0 log: > tcgetattr(8,jtermios.Termios@5a77a7f9) All comments welcome. be Kusti