View Javadoc
1   /*
2    * junixsocket
3    *
4    * Copyright 2009-2024 Christian Kohlschütter
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.newsclub.net.unix;
19  
20  import java.io.FileDescriptor;
21  import java.io.IOException;
22  import java.net.Socket;
23  import java.net.SocketException;
24  
25  class AFUNIXSocketImpl extends AFSocketImpl<AFUNIXSocketAddress> {
26    protected AFUNIXSocketImpl(FileDescriptor fdObj) {
27      super(AFUNIXSocketAddress.AF_UNIX, fdObj);
28    }
29  
30    /**
31     * Changes the behavior to be somewhat lenient with respect to the specification.
32     *
33     * In particular, we ignore calls to {@link Socket#getTcpNoDelay()} and
34     * {@link Socket#setTcpNoDelay(boolean)}.
35     */
36    static final class Lenient extends AFUNIXSocketImpl {
37      Lenient(FileDescriptor fdObj) throws SocketException {
38        super(fdObj);
39      }
40  
41      @Override
42      public void setOption(int optID, Object value) throws SocketException {
43        super.setOptionLenient(optID, value);
44      }
45  
46      @Override
47      public Object getOption(int optID) throws SocketException {
48        return super.getOptionLenient(optID);
49      }
50    }
51  
52    AFUNIXSocketCredentials getPeerCredentials() throws IOException {
53      return NativeUnixSocket.peerCredentials(fd, new AFUNIXSocketCredentials());
54    }
55  
56    final FileDescriptor[] getReceivedFileDescriptors() {
57      return ancillaryDataSupport.getReceivedFileDescriptors();
58    }
59  
60    final void clearReceivedFileDescriptors() {
61      ancillaryDataSupport.clearReceivedFileDescriptors();
62    }
63  
64    final void receiveFileDescriptors(int[] fds) throws IOException {
65      ancillaryDataSupport.receiveFileDescriptors(fds);
66    }
67  
68    final void setOutboundFileDescriptors(FileDescriptor... fdescs) throws IOException {
69      ancillaryDataSupport.setOutboundFileDescriptors(fdescs);
70    }
71  
72    final boolean hasOutboundFileDescriptors() {
73      return ancillaryDataSupport.hasOutboundFileDescriptors();
74    }
75  }