Source code: com/act365/net/SocketWrenchSession.java
1 /*
2 * JSocket Wrench
3 *
4 * Copyright (C) act365.com October 2003
5 *
6 * Web site: http://www.act365.com/wrench
7 * E-mail: developers@act365.com
8 *
9 * The JSocket Wrench library adds support for low-level Internet protocols
10 * to the Java programming language.
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the Free
14 * Software Foundation; either version 2 of the License, or (at your option)
15 * any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
20 * Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * this program; if not, write to the Free Software Foundation, Inc.,
24 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 */
26
27 package com.act365.net;
28
29 import java.net.*;
30
31 /**
32 * Manages the housekeeping tasks (mostly on Windows) associated with
33 * the startup and the shutdown of the library.
34 */
35
36 public class SocketWrenchSession {
37
38 /**
39 Loads the native library and starts Winsock 2 on Windows.
40 */
41
42 static {
43 try {
44 System.loadLibrary("com_act365_net_Sockets");
45 _startup();
46 } catch ( UnsatisfiedLinkError ule ){
47 String libpath = System.getProperty("java.library.path");
48 System.err.println("com_act365_net_Sockets not found on library path " + libpath );
49 } catch ( Exception e ) {
50 System.err.println( e.getMessage() );
51 }
52 }
53
54 native static int _startup() throws SocketException ;
55
56 /**
57 Releases Winsock 2 resources on Windows.
58 */
59
60 protected void finalize() {
61 try {
62 _shutdown();
63 } catch ( SocketException e ) {
64 System.err.println( e.getMessage() );
65 }
66 }
67
68 native static int _shutdown() throws SocketException ;
69 }
70