blob: a885fa149bb0301d88501cc1b6799173e39cbaee [file] [log] [blame]
Mark Slee83c52a82006-06-07 06:51:18 +00001package com.facebook.thrift.transport;
2
3import java.io.IOException;
4import java.net.ServerSocket;
5import java.net.Socket;
6
7/**
8 * Wrapper around ServerSocket for Thrift.
9 *
10 * @author Mark Slee <mcslee@facebook.com>
11 */
12public 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}