Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
b10bb9f8bf | ||
|
55a15ad75d |
@ -132,20 +132,29 @@ public final class DesktopConnection implements Closeable {
|
|||||||
return controlSocket;
|
return controlSocket;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() throws IOException {
|
public void shutdown() throws IOException {
|
||||||
if (videoSocket != null) {
|
if (videoSocket != null) {
|
||||||
videoSocket.shutdownInput();
|
videoSocket.shutdownInput();
|
||||||
videoSocket.shutdownOutput();
|
videoSocket.shutdownOutput();
|
||||||
videoSocket.close();
|
|
||||||
}
|
}
|
||||||
if (audioSocket != null) {
|
if (audioSocket != null) {
|
||||||
audioSocket.shutdownInput();
|
audioSocket.shutdownInput();
|
||||||
audioSocket.shutdownOutput();
|
audioSocket.shutdownOutput();
|
||||||
audioSocket.close();
|
|
||||||
}
|
}
|
||||||
if (controlSocket != null) {
|
if (controlSocket != null) {
|
||||||
controlSocket.shutdownInput();
|
controlSocket.shutdownInput();
|
||||||
controlSocket.shutdownOutput();
|
controlSocket.shutdownOutput();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close() throws IOException {
|
||||||
|
if (videoSocket != null) {
|
||||||
|
videoSocket.close();
|
||||||
|
}
|
||||||
|
if (audioSocket != null) {
|
||||||
|
audioSocket.close();
|
||||||
|
}
|
||||||
|
if (controlSocket != null) {
|
||||||
controlSocket.close();
|
controlSocket.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,11 @@ package com.genymobile.scrcpy;
|
|||||||
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import java.io.FileDescriptor;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.io.PrintStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log both to Android logger (so that logs are visible in "adb logcat") and standard output/error (so that they are visible in the terminal
|
* Log both to Android logger (so that logs are visible in "adb logcat") and standard output/error (so that they are visible in the terminal
|
||||||
* directly).
|
* directly).
|
||||||
@ -11,6 +16,9 @@ public final class Ln {
|
|||||||
private static final String TAG = "scrcpy";
|
private static final String TAG = "scrcpy";
|
||||||
private static final String PREFIX = "[server] ";
|
private static final String PREFIX = "[server] ";
|
||||||
|
|
||||||
|
private static final PrintStream consoleOut = new PrintStream(new FileOutputStream(FileDescriptor.out));
|
||||||
|
private static final PrintStream consoleErr = new PrintStream(new FileOutputStream(FileDescriptor.err));
|
||||||
|
|
||||||
enum Level {
|
enum Level {
|
||||||
VERBOSE, DEBUG, INFO, WARN, ERROR
|
VERBOSE, DEBUG, INFO, WARN, ERROR
|
||||||
}
|
}
|
||||||
@ -21,6 +29,12 @@ public final class Ln {
|
|||||||
// not instantiable
|
// not instantiable
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void disableSystemStreams() {
|
||||||
|
PrintStream nullStream = new PrintStream(new NullOutputStream());
|
||||||
|
System.setOut(nullStream);
|
||||||
|
System.setErr(nullStream);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the log level.
|
* Initialize the log level.
|
||||||
* <p>
|
* <p>
|
||||||
@ -39,30 +53,30 @@ public final class Ln {
|
|||||||
public static void v(String message) {
|
public static void v(String message) {
|
||||||
if (isEnabled(Level.VERBOSE)) {
|
if (isEnabled(Level.VERBOSE)) {
|
||||||
Log.v(TAG, message);
|
Log.v(TAG, message);
|
||||||
System.out.print(PREFIX + "VERBOSE: " + message + '\n');
|
consoleOut.print(PREFIX + "VERBOSE: " + message + '\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void d(String message) {
|
public static void d(String message) {
|
||||||
if (isEnabled(Level.DEBUG)) {
|
if (isEnabled(Level.DEBUG)) {
|
||||||
Log.d(TAG, message);
|
Log.d(TAG, message);
|
||||||
System.out.print(PREFIX + "DEBUG: " + message + '\n');
|
consoleOut.print(PREFIX + "DEBUG: " + message + '\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void i(String message) {
|
public static void i(String message) {
|
||||||
if (isEnabled(Level.INFO)) {
|
if (isEnabled(Level.INFO)) {
|
||||||
Log.i(TAG, message);
|
Log.i(TAG, message);
|
||||||
System.out.print(PREFIX + "INFO: " + message + '\n');
|
consoleOut.print(PREFIX + "INFO: " + message + '\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void w(String message, Throwable throwable) {
|
public static void w(String message, Throwable throwable) {
|
||||||
if (isEnabled(Level.WARN)) {
|
if (isEnabled(Level.WARN)) {
|
||||||
Log.w(TAG, message, throwable);
|
Log.w(TAG, message, throwable);
|
||||||
System.err.print(PREFIX + "WARN: " + message + '\n');
|
consoleErr.print(PREFIX + "WARN: " + message + '\n');
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
throwable.printStackTrace();
|
throwable.printStackTrace(consoleErr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -74,9 +88,9 @@ public final class Ln {
|
|||||||
public static void e(String message, Throwable throwable) {
|
public static void e(String message, Throwable throwable) {
|
||||||
if (isEnabled(Level.ERROR)) {
|
if (isEnabled(Level.ERROR)) {
|
||||||
Log.e(TAG, message, throwable);
|
Log.e(TAG, message, throwable);
|
||||||
System.err.print(PREFIX + "ERROR: " + message + "\n");
|
consoleErr.print(PREFIX + "ERROR: " + message + '\n');
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
throwable.printStackTrace();
|
throwable.printStackTrace(consoleErr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -84,4 +98,21 @@ public final class Ln {
|
|||||||
public static void e(String message) {
|
public static void e(String message) {
|
||||||
e(message, null);
|
e(message, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class NullOutputStream extends OutputStream {
|
||||||
|
@Override
|
||||||
|
public void write(byte[] b) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(byte[] b, int off, int len) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(int b) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -163,6 +163,8 @@ public final class Server {
|
|||||||
asyncProcessor.stop();
|
asyncProcessor.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
connection.shutdown();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
initThread.join();
|
initThread.join();
|
||||||
for (AsyncProcessor asyncProcessor : asyncProcessors) {
|
for (AsyncProcessor asyncProcessor : asyncProcessors) {
|
||||||
@ -187,7 +189,7 @@ public final class Server {
|
|||||||
try {
|
try {
|
||||||
internalMain(args);
|
internalMain(args);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
t.printStackTrace();
|
Ln.e(t.getMessage(), t);
|
||||||
status = 1;
|
status = 1;
|
||||||
} finally {
|
} finally {
|
||||||
// By default, the Java process exits when all non-daemon threads are terminated.
|
// By default, the Java process exits when all non-daemon threads are terminated.
|
||||||
@ -204,6 +206,7 @@ public final class Server {
|
|||||||
|
|
||||||
Options options = Options.parse(args);
|
Options options = Options.parse(args);
|
||||||
|
|
||||||
|
Ln.disableSystemStreams();
|
||||||
Ln.initLogLevel(options.getLogLevel());
|
Ln.initLogLevel(options.getLogLevel());
|
||||||
|
|
||||||
Ln.i("Device: [" + Build.MANUFACTURER + "] " + Build.BRAND + " " + Build.MODEL + " (Android " + Build.VERSION.RELEASE + ")");
|
Ln.i("Device: [" + Build.MANUFACTURER + "] " + Build.BRAND + " " + Build.MODEL + " (Android " + Build.VERSION.RELEASE + ")");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user