Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add channel open check before writting #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions Expect.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,15 @@ public void run() {
byte[] buffer = new byte[1024];
try {
for (int n = 0; n != -1; n = input.read(buffer)) {
out.write(buffer, 0, n);
if (duplicatedTo != null) {
String toWrite = new String(buffer, 0, n);
duplicatedTo.append(toWrite); // no Exception will be thrown
// if don't check to see if channel is still open to write to - Broken Pipe Exception will be thrown
if (pipe.source().isOpen()) {
out.write(buffer, 0, n);
if (duplicatedTo != null) {
String toWrite = new String(buffer, 0, n);
duplicatedTo.append(toWrite); // no Exception will be thrown
}
} else {
log.warn("Socket Channel is no longer open to write " + new String(buffer));
}
}
log.debug("EOF from InputStream");
Expand Down