-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pass credentials/fds via UNIX sockets. SOCK_SEQPACKET support.
- Loading branch information
Showing
13 changed files
with
440 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright 2021 Odnoklassniki Ltd, Mail.Ru Group | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package one.nio.net; | ||
|
||
import java.util.Arrays; | ||
|
||
public final class Msg { | ||
public static final int SCM_RIGHTS = 1; | ||
public static final int SCM_CREDENTIALS = 2; | ||
|
||
private byte[] data; | ||
private int cmsgType; | ||
private int[] cmsgData; | ||
|
||
public Msg(int capacity) { | ||
this.data = new byte[capacity]; | ||
} | ||
|
||
public Msg(byte[] data) { | ||
this.data = data; | ||
} | ||
|
||
public byte[] data() { | ||
return data; | ||
} | ||
|
||
public int cmsgType() { | ||
return cmsgType; | ||
} | ||
|
||
public int[] cmsgData() { | ||
return cmsgData; | ||
} | ||
|
||
public Msg withCmsg(int type, int... data) { | ||
if (cmsgType != 0) { | ||
throw new IllegalStateException("cmsg already set"); | ||
} | ||
cmsgType = type; | ||
cmsgData = data; | ||
return this; | ||
} | ||
|
||
public Msg withFd(int fd) { | ||
return withCmsg(SCM_RIGHTS, fd); | ||
} | ||
|
||
public Msg withFd(int... fds) { | ||
return withCmsg(SCM_RIGHTS, fds); | ||
} | ||
|
||
public Msg withCred(int pid, int uid, int gid) { | ||
return withCmsg(SCM_CREDENTIALS, pid, uid, gid); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder sb = new StringBuilder("Msg(").append(data == null ? 0 : data.length); | ||
if (cmsgType != 0) { | ||
sb.append(cmsgType == SCM_RIGHTS ? " + SCM_RIGHTS" : " + SCM_CREDENTIALS"); | ||
sb.append(Arrays.toString(cmsgData)); | ||
} | ||
return sb.append(')').toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.