Skip to content

Commit

Permalink
gh-24 some sonar fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Unknow0 committed Dec 17, 2023
1 parent d2c3568 commit b800dd8
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class HttpConnection extends NIOConnection {
* create new RequestBuilder
* @param pool
*/
public HttpConnection(ExecutorService executor, ServletContextImpl ctx, int keepAliveIdle) {
protected HttpConnection(ExecutorService executor, ServletContextImpl ctx, int keepAliveIdle) {
this.executor = executor;
this.keepAliveIdle = keepAliveIdle;
this.ctx = ctx;
Expand All @@ -56,29 +56,13 @@ public final void onRead() throws InterruptedException {
return;
if (!p.init(this))
return;
// int i = BuffersUtils.indexOf(pendingRead, CRLF2, 0, MAX_START_SIZE);
// if (i == -1)
// return;
// if (i == -2) {
// error(HttpError.BAD_REQUEST);
// return;
// }
f = executor.submit(p);
}

@Override
public final void onWrite() { // OK
}

// private final void error(HttpError e) {
// try {
// OutputStream out = getOut();
// out.write(e.empty());
// out.close();
// } catch (@SuppressWarnings("unused") IOException ex) { // OK
// }
// }

private void cleanup() {
f.cancel(true);
p.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,17 @@ private void parseParam() {
if (parameter != null)
return;
parameter = new HashMap<>();
Map<String, List<String>> p = new HashMap<>(queryParam);
Map<String, List<String>> map = new HashMap<>(queryParam);

try {
if ("POST".equals(getMethod()) && "application/x-www-form-urlencoded".equalsIgnoreCase(getContentType()))
parseContentParam(p);
parseContentParam(map);
} catch (IOException e) {
logger.error("failed to parse params from content", e);
}

String[] s = new String[0];
for (Entry<String, List<String>> e : p.entrySet())
for (Entry<String, List<String>> e : map.entrySet())
parameter.put(e.getKey(), e.getValue().toArray(s));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public class NIOConnection {

private static final InetSocketAddress DISCONECTED = InetSocketAddress.createUnresolved("", 0);

// private final Pool<NIOConnection> pool;

/** the data waiting to be wrote */
public final Buffers pendingWrite = new Buffers();
/** the data waiting to be handled */
Expand All @@ -46,9 +44,8 @@ public class NIOConnection {
private long lastRead;
private long lastWrite;

// protected NIOConnection(Pool<NIOConnection> pool) {
// this.pool = pool;
// }
protected NIOConnection() {
}

final void init(SelectionKey key) {
this.key = key;
Expand Down Expand Up @@ -84,7 +81,7 @@ protected void onWrite() throws InterruptedException, IOException { // for overr
* @throws InterruptedException
* @throws IOException
*/
protected void onFree() throws InterruptedException, IOException { // for override
protected void onFree() throws IOException { // for override
}

/**
Expand Down Expand Up @@ -240,12 +237,11 @@ public boolean closed(long now, boolean stop) {
* @throws IOException
* @throws InterruptedException
*/
public final void free() throws InterruptedException, IOException {
public final void free() throws IOException {
out.close();
pendingWrite.clear();
pendingRead.clear();
onFree();
// pool.free(this);
}

@SuppressWarnings("resource")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ protected final void selected(SelectionKey key) throws IOException, InterruptedE
if (key.isValid() && key.isWritable()) {
try {
h.writeInto(channel, buf);
} catch (InterruptedException e) {
logger.error("failed to write {}", h, e);
Thread.currentThread().interrupt();
} catch (Exception e) {
logger.error("failed to write {}", h, e);
channel.close();
Expand All @@ -97,6 +100,9 @@ protected final void selected(SelectionKey key) throws IOException, InterruptedE
if (key.isValid() && key.isReadable()) {
try {
h.readFrom(channel, buf);
} catch (InterruptedException e) {
logger.error("failed to read {}", h, e);
Thread.currentThread().interrupt();
} catch (Exception e) {
logger.error("failed to read {}", h, e);
channel.close();
Expand Down Expand Up @@ -129,7 +135,7 @@ protected void onSelect(boolean close) throws InterruptedException {
}
try {
co.free();
} catch (InterruptedException | IOException e) {
} catch (Exception e) {
logger.warn("Failed to free connection {}", co, e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.google.protobuf.Parser;

import unknow.server.nio.NIOConnection;
import unknow.server.util.pool.Pool;

/**
* @author unknow
Expand All @@ -21,8 +20,7 @@ public abstract class ProtobufConnection<T> extends NIOConnection {
private final LimitedInputStream limited;

@SuppressWarnings("resource")
protected ProtobufConnection(Pool<NIOConnection> pool, Parser<T> parser) {
// super(pool);
protected ProtobufConnection(Parser<T> parser) {
this.parser = parser;
this.limited = new LimitedInputStream(getIn());
}
Expand Down Expand Up @@ -56,17 +54,4 @@ private final int readInt(InputStream in) throws IOException {
return -1;
return CodedInputStream.readRawVarint32(read, in);
}

@Override
public final void onWrite() { // OK
}

@Override
public final boolean closed(long now, boolean close) {
return close;
}

@Override
public final void onFree() { // OK
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ public void read(Buffers buf, int l, boolean wait) throws InterruptedException {
try {
if (wait)
awaitContent();
if (l == 0 || head == null)
if (len == 0 || head == null)
return;

if (l >= len) { // move all content
Expand Down

0 comments on commit b800dd8

Please sign in to comment.