Skip to content
Permalink
Browse files

Formatting / coding style

  • Loading branch information...
apangin committed Jun 9, 2019
1 parent f2e2367 commit 050e1bdef6cd2a3ea3e2ff780c2e2d8458ee9380
@@ -44,7 +44,7 @@
public final boolean isOpen() {
return fd >= 0;
}

@Override
public NativeSocket accept() throws IOException {
return new NativeSocket(accept0(false));
@@ -23,7 +23,6 @@
import java.io.RandomAccessFile;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.nio.ByteBuffer;
import java.nio.channels.ByteChannel;

@@ -179,11 +178,4 @@ public static Socket fromFD(int fd) throws IOException {
}
throw new IOException("Operation is not supported");
}

public static int getFreePort() throws IOException {
ServerSocket serverSocket = new ServerSocket(0);
int localPort = serverSocket.getLocalPort();
serverSocket.close();
return localPort;
}
}
@@ -92,17 +92,17 @@ static int is_udp_socket(int fd) {
return getsockopt(fd, SOL_SOCKET, SO_TYPE, &type, &length) == 0 && type == SOCK_DGRAM;
}

static int get_int_socket_opt(int fd, int level, int optname){
int optval = 0;
static jint get_int_socket_opt(int fd, int level, int optname) {
int optval;
socklen_t length = sizeof(optval);
if(getsockopt(fd, level, optname, &optval, &length) == 0){
if (getsockopt(fd, level, optname, &optval, &length) == 0) {
return optval;
}
return 0;
}

static int get_bool_socket_opt(int fd, int level, int optname){
return get_int_socket_opt(fd, level, optname) > 0;
static jboolean get_bool_socket_opt(int fd, int level, int optname) {
return get_int_socket_opt(fd, level, optname) ? JNI_TRUE : JNI_FALSE;
}

static void sockaddr_to_java(JNIEnv* env, jbyteArray buffer, struct sockaddr_storage* sa, int err) {
@@ -544,8 +544,8 @@ Java_one_nio_net_NativeSocket_getTimeout(JNIEnv* env, jobject self) {
int fd = (*env)->GetIntField(env, self, f_fd);
struct timeval tv;
socklen_t len = sizeof(tv);
if(getsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, &len) == 0){
return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
if (getsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, &len) == 0) {
return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
}
return 0;
}
@@ -650,7 +650,6 @@ Java_one_nio_net_NativeSocket_getSendBuffer(JNIEnv* env, jobject self) {
JNIEXPORT void JNICALL
Java_one_nio_net_NativeSocket_setTos(JNIEnv* env, jobject self, jint tos) {
int fd = (*env)->GetIntField(env, self, f_fd);
// todo: tos mask, IPV6_FLOWINFO_SEND, IPV6_TCLASS?
setsockopt(fd, IPPROTO_IP, IP_TOS, &tos, sizeof(tos));
}

@@ -18,12 +18,12 @@

import one.nio.net.ConnectionString;
import one.nio.net.Socket;
import one.nio.net.SocketUtil;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.SocketException;

import static org.junit.Assert.assertEquals;
@@ -42,7 +42,7 @@

@BeforeClass
public static void beforeAll() throws IOException {
int availablePort = Socket.getFreePort();
int availablePort = SocketUtil.getFreePort();
server = new TestServer(HttpServerConfigFactory.create(availablePort));
server.start();
client = new HttpClient(new ConnectionString("http://127.0.0.1:" + availablePort));
@@ -17,7 +17,7 @@
package one.nio.http;

import one.nio.net.ConnectionString;
import one.nio.net.Socket;
import one.nio.net.SocketUtil;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -43,7 +43,7 @@

@BeforeClass
public static void beforeAll() throws IOException {
int availablePort = Socket.getFreePort();
int availablePort = SocketUtil.getFreePort();
server = new TestServer(HttpServerConfigFactory.create(availablePort));
server.start();
client = new HttpClient(new ConnectionString("http://127.0.0.1:" + availablePort));
@@ -17,14 +17,12 @@
package one.nio.http;

import one.nio.config.ConfigParser;
import one.nio.mgt.ThreadDumper;
import one.nio.net.ConnectionString;
import one.nio.net.Socket;
import one.nio.net.SocketUtil;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import static org.junit.Assert.assertEquals;
@@ -35,7 +33,7 @@

@BeforeClass
public static void beforeAll() throws IOException {
int availablePort = Socket.getFreePort();
int availablePort = SocketUtil.getFreePort();

String config =
"acceptors:\n" +
@@ -45,7 +43,7 @@ public static void beforeAll() throws IOException {
" router2a: r2a.example.com\n" +
" router2b: R2B.example.com\n";

server = new HttpServer(ConfigParser.parse(config, HttpServerConfig.class),
server = new HttpServer(ConfigParser.parse(config, HttpServerConfig.class),
new Router0(), new Router1(), new Router2());
server.start();
client = new HttpClient(new ConnectionString("http://127.0.0.1:" + availablePort));
@@ -116,7 +114,7 @@ public Response get2() {
}

@Path("/set")
public Response set2() throws IOException {
public Response set2() {
return Response.ok("set_response_2");
}
}
@@ -22,7 +22,6 @@
import java.io.IOException;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;

public class SocketTest {

@@ -76,10 +75,8 @@ public void testJavaServerSocketOpts() throws IOException {
SocketTest.testSocketOpts(new JavaServerSocket(), true);
}

public static void testSocketOpts(Socket socket, boolean datagram)
{
try
{
public static void testSocketOpts(Socket socket, boolean datagram) {
try {
socket.setBlocking(false);
assertFalse(socket.isBlocking());
socket.setBlocking(true);
@@ -127,8 +124,7 @@ public static void testSocketOpts(Socket socket, boolean datagram)
socket.setRecvBuffer(4 * 1048);
assertEquals(4 * 1048, socket.getRecvBuffer());

if (!(socket instanceof JavaServerSocket))
{
if (!(socket instanceof JavaServerSocket)) {
assertTrue(socket.getSendBuffer() > 0);
socket.setSendBuffer(8 * 1048 + 12345);
assertEquals(8 * 1048 + 12345, socket.getSendBuffer());
@@ -137,13 +133,9 @@ public static void testSocketOpts(Socket socket, boolean datagram)
socket.setTos(96);
assertEquals(96, socket.getTos());
}
}
catch (Exception e)
{
} catch (Exception e) {
throw e;
}
finally
{
} finally {
socket.close();
}
}
@@ -18,7 +18,7 @@

import one.nio.config.ConfigParser;
import one.nio.net.ConnectionString;
import one.nio.net.Socket;
import one.nio.net.SocketUtil;
import one.nio.rpc.stream.BidiStream;
import one.nio.serial.sample.Message;
import one.nio.serial.sample.Sample;
@@ -45,7 +45,7 @@

@BeforeClass
public static void setup() throws Exception {
int availablePort = Socket.getFreePort();
int availablePort = SocketUtil.getFreePort();
ServerConfig config = ConfigParser.parse("acceptors:\n - port: " + availablePort, ServerConfig.class);
server = new RpcServer<>(config, new TestServiceImpl());
server.start();

0 comments on commit 050e1bd

Please sign in to comment.
You can’t perform that action at this time.