mirror of https://github.com/M66B/FairEmail.git
Subtract send buffer size
This commit is contained in:
parent
858f2038f3
commit
5a629dc17b
|
@ -16,6 +16,7 @@
|
|||
|
||||
package com.sun.mail.smtp;
|
||||
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.io.*;
|
||||
|
@ -1300,6 +1301,7 @@ public class SMTPTransport extends Transport {
|
|||
try {
|
||||
mailFrom();
|
||||
rcptTo();
|
||||
|
||||
eu.faircode.email.ObjectHolder<Integer> total = new eu.faircode.email.ObjectHolder<>();
|
||||
total.value = 0;
|
||||
this.message.writeTo(new OutputStream(){
|
||||
|
@ -1308,10 +1310,37 @@ public class SMTPTransport extends Transport {
|
|||
total.value++;
|
||||
}
|
||||
});
|
||||
|
||||
Integer _fd = null;
|
||||
try {
|
||||
_fd = ParcelFileDescriptor.fromSocket(serverSocket).getFd();
|
||||
} catch (Throwable ex) {
|
||||
eu.faircode.email.Log.w(ex);
|
||||
}
|
||||
final Integer fd = _fd;
|
||||
|
||||
TraceOutputStream.IReport reporter =
|
||||
(TraceOutputStream.IReport) session.getProperties()
|
||||
.get("mail." + name + ".reporter");
|
||||
traceOutput.setReporter(total.value, reporter);
|
||||
traceOutput.setReporter(total.value, new TraceOutputStream.IReport() {
|
||||
@Override
|
||||
public void report(int pos, int total) {
|
||||
if (reporter == null)
|
||||
return;
|
||||
|
||||
int q = 0;
|
||||
if (fd != null)
|
||||
q = eu.faircode.email.ConnectionHelper.jni_socket_get_send_buffer(fd);
|
||||
if (q > pos)
|
||||
q = pos;
|
||||
|
||||
int sent = pos - q;
|
||||
if (sent > total)
|
||||
sent = total;
|
||||
|
||||
reporter.report(sent, total);
|
||||
}
|
||||
});
|
||||
if (chunkSize > 0 && supportsExtension("CHUNKING")) {
|
||||
/*
|
||||
* Use BDAT to send the data in chunks.
|
||||
|
|
|
@ -89,6 +89,8 @@ public class ConnectionHelper {
|
|||
|
||||
public static native int jni_socket_keep_alive(int fd, int seconds);
|
||||
|
||||
public static native int jni_socket_get_send_buffer(int fd);
|
||||
|
||||
static class NetworkState {
|
||||
private Boolean connected = null;
|
||||
private Boolean suitable = null;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <errno.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include "compact_enc_det/compact_enc_det.h"
|
||||
#include "cld_3/src/nnet_language_identifier.h"
|
||||
|
@ -140,3 +141,15 @@ Java_eu_faircode_email_ConnectionHelper_jni_1socket_1keep_1alive(
|
|||
|
||||
return res;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_eu_faircode_email_ConnectionHelper_jni_1socket_1get_1send_1buffer(
|
||||
JNIEnv *env, jclass clazz,
|
||||
jint fd) {
|
||||
int queued = 0;
|
||||
int res = ioctl(fd, TIOCOUTQ, &queued);
|
||||
if (res != 0)
|
||||
log_android(ANDROID_LOG_DEBUG, "ioctl(TIOCOUTQ) res=%d queued=%d", res, queued);
|
||||
return (res == 0 ? queued : 0);
|
||||
}
|
Loading…
Reference in New Issue