Skip to content

Commit 2662a46

Browse files
committed
Merge pull request AsyncHttpClient#390 from plouh/ahc-1.7.x
Fix sending multipart bodies through SocketChannel
2 parents 296e71c + fb2daac commit 2662a46

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/main/java/com/ning/http/multipart/FilePart.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ public FilePart(String name, String fileName, File file, String contentType, Str
147147
*/
148148
protected void sendDispositionHeader(OutputStream out) throws IOException {
149149
String filename = this.source.getFileName();
150+
super.sendDispositionHeader(out);
150151
if (filename != null) {
151-
super.sendDispositionHeader(out);
152152
out.write(FILE_NAME_BYTES);
153153
out.write(QUOTE_BYTES);
154154
out.write(MultipartEncodingUtil.getAsciiBytes(filename));

src/main/java/com/ning/http/multipart/MultipartBody.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -578,18 +578,21 @@ private long writeToTarget(WritableByteChannel target, ByteArrayOutputStream byt
578578
final SocketChannel channel = (SocketChannel) target;
579579
channel.register(selector, SelectionKey.OP_WRITE);
580580

581-
while (written < byteWriter.size() && selector.select() != 0) {
581+
while (written < byteWriter.size()) {
582+
selector.select(1000);
583+
maxSpin++;
582584
final Set<SelectionKey> selectedKeys = selector.selectedKeys();
583585

584586
for (SelectionKey key : selectedKeys) {
585587
if (key.isWritable()) {
586588
written += target.write(message);
589+
maxSpin = 0;
587590
}
588591
}
589-
}
590592

591-
if (written < byteWriter.size()) {
592-
throw new IOException("Unable to write on channel " + target);
593+
if (maxSpin >= 10) {
594+
throw new IOException("Unable to write on channel " + target);
595+
}
593596
}
594597
} finally {
595598
selector.close();

0 commit comments

Comments
 (0)