Skip to content

Commit

Permalink
0.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
Immueggpain authored and Immueggpain committed Dec 28, 2019
1 parent a3b14f7 commit cf5e190
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.github.immueggpain</groupId>
<artifactId>simple-streaming</artifactId>
<version>0.0.8</version>
<version>0.0.9</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
subcommands = { HelpCommand.class, StreamUpload.class, StreamServer.class, Serve.class })
public class Launcher implements Callable<Void> {

public static final String VERSTR = "0.0.8";
public static final String VERSTR = "0.0.9";
public static final int LOCAL_PORT = 2233;
public static final int LOCAL_OVPN_PORT = 1194;
public static final int BUFLEN = 1024 * 64;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private void download_thread() {
private void download_thread(Socket socket) {
try (Socket socket_ = socket) {
OutputStream os = socket.getOutputStream();
CircularByteBuffer buf = new CircularByteBuffer(Launcher.BUFLEN);
CircularByteBuffer buf = new CircularByteBuffer(Launcher.BUFLEN * 4);
byte[] bs = new byte[Launcher.BUFLEN];

// add me to active downloaders
Expand All @@ -94,6 +94,10 @@ private void download_thread(Socket socket) {
}
} catch (Exception e) {
e.printStackTrace();
} finally {
synchronized (activeDownloaders) {
activeDownloaders.remove(socket);
}
}
}

Expand Down Expand Up @@ -133,7 +137,8 @@ private void upload_thread(Socket socket) {
for (Downloader downloader : activeDownloaders.values()) {
int n = downloader.buf.put(buf, 0, len);
int missing = len - n;
System.out.println("missing " + missing);
if (missing > 0)
System.out.println("missing " + missing);
}
}
}
Expand All @@ -147,22 +152,22 @@ private void remove_expired_player_thread() {
while (true) {
synchronized (activeDownloaders) {
long now = System.currentTimeMillis();
System.out.println("==player check==" + now);
System.out.println("==downloader check==" + now);
for (Iterator<Entry<Socket, Downloader>> iterator = activeDownloaders.entrySet().iterator(); iterator
.hasNext();) {
Entry<Socket, Downloader> entry = iterator.next();
Socket key = entry.getKey();
Downloader playerInfo = entry.getValue();
long last = playerInfo.t;
if (now - last > 20000 && playerInfo.buf.available() > 0) {
System.out.println(String.format("dead player: %s", key.getRemoteSocketAddress()));
System.out.println(String.format("dead downloader: %s", key.getRemoteSocketAddress()));
iterator.remove();
try {
key.close();
} catch (IOException e) {
}
} else {
System.out.println(String.format("active player: %s", key.getRemoteSocketAddress()));
System.out.println(String.format("active downloader: %s", key.getRemoteSocketAddress()));
}
}
}
Expand Down

0 comments on commit cf5e190

Please sign in to comment.