Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 1 | package com.facebook.thrift.transport; |
| 2 | |
| 3 | import java.io.IOException; |
| 4 | import java.net.ServerSocket; |
| 5 | import java.net.Socket; |
| 6 | |
| 7 | /** |
| 8 | * Wrapper around ServerSocket for Thrift. |
| 9 | * |
| 10 | * @author Mark Slee <mcslee@facebook.com> |
| 11 | */ |
| 12 | public class TServerSocket extends TServerTransport { |
| 13 | |
| 14 | private ServerSocket serverSocket_; |
| 15 | |
| 16 | public TServerSocket(ServerSocket serverSocket) { |
| 17 | serverSocket_ = serverSocket; |
| 18 | } |
| 19 | |
| 20 | public void listen() throws TTransportException {} |
| 21 | |
| 22 | protected TSocket acceptImpl() throws TTransportException { |
| 23 | if (serverSocket_ == null) { |
| 24 | throw new TTransportException("No underlying server socket."); |
| 25 | } |
| 26 | try { |
| 27 | Socket result = serverSocket_.accept(); |
| 28 | return new TSocket(result); |
| 29 | } catch (IOException iox) { |
| 30 | throw new TTransportException(iox); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | public void close() { |
| 35 | if (serverSocket_ != null) { |
| 36 | try { |
| 37 | serverSocket_.close(); |
| 38 | } catch (IOException iox) { |
| 39 | System.err.println("WARNING: Could not close server socket: " + |
| 40 | iox.getMessage()); |
| 41 | } |
| 42 | serverSocket_ = null; |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | } |