View Javadoc

1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  
28  package org.apache.http.impl;
29  
30  import java.io.IOException;
31  import java.net.Socket;
32  
33  import org.apache.http.annotation.NotThreadSafe;
34  import org.apache.http.params.HttpConnectionParams;
35  import org.apache.http.params.HttpParams;
36  
37  /**
38   * Default implementation of a server-side HTTP connection.
39   * <p>
40   * The following parameters can be used to customize the behavior of this
41   * class:
42   * <ul>
43   *  <li>{@link org.apache.http.params.CoreProtocolPNames#HTTP_ELEMENT_CHARSET}</li>
44   *  <li>{@link org.apache.http.params.CoreConnectionPNames#TCP_NODELAY}</li>
45   *  <li>{@link org.apache.http.params.CoreConnectionPNames#SO_TIMEOUT}</li>
46   *  <li>{@link org.apache.http.params.CoreConnectionPNames#SO_LINGER}</li>
47   *  <li>{@link org.apache.http.params.CoreConnectionPNames#SO_KEEPALIVE}</li>
48   *  <li>{@link org.apache.http.params.CoreConnectionPNames#SOCKET_BUFFER_SIZE}</li>
49   *  <li>{@link org.apache.http.params.CoreConnectionPNames#MAX_LINE_LENGTH}</li>
50   *  <li>{@link org.apache.http.params.CoreConnectionPNames#MAX_HEADER_COUNT}</li>
51   *  <li>{@link org.apache.http.params.CoreConnectionPNames#MIN_CHUNK_LIMIT}</li>
52   * </ul>
53   *
54   * @since 4.0
55   */
56  @NotThreadSafe
57  public class DefaultHttpServerConnection extends SocketHttpServerConnection {
58  
59      public DefaultHttpServerConnection() {
60          super();
61      }
62  
63      @Override
64      public void bind(final Socket socket, final HttpParams params) throws IOException {
65          if (socket == null) {
66              throw new IllegalArgumentException("Socket may not be null");
67          }
68          if (params == null) {
69              throw new IllegalArgumentException("HTTP parameters may not be null");
70          }
71          assertNotOpen();
72          socket.setTcpNoDelay(HttpConnectionParams.getTcpNoDelay(params));
73          socket.setSoTimeout(HttpConnectionParams.getSoTimeout(params));
74          socket.setKeepAlive(HttpConnectionParams.getSoKeepalive(params));
75  
76          int linger = HttpConnectionParams.getLinger(params);
77          if (linger >= 0) {
78              socket.setSoLinger(linger > 0, linger);
79          }
80          super.bind(socket, params);
81      }
82  
83  }