mirror of
https://gitlab.com/Theopse/fbi-i18n-zh.git
synced 2025-04-29 21:06:38 +08:00
Simplify sending of URLs in servefile, make socket operations cancellable by the user.
This commit is contained in:
parent
9182ebfa00
commit
22b26c2f34
@ -67,20 +67,9 @@ try:
|
|||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
sock.connect((ip, 5000))
|
sock.connect((ip, 5000))
|
||||||
|
|
||||||
try:
|
|
||||||
payloadBytes = bytes(payload, "ascii")
|
|
||||||
except:
|
|
||||||
payloadBytes = payload.encode("ascii")
|
payloadBytes = payload.encode("ascii")
|
||||||
|
|
||||||
networkPayload = struct.pack('!L', len(payloadBytes)) + payloadBytes
|
sock.sendall(struct.pack('!L', len(payloadBytes)) + payloadBytes)
|
||||||
|
|
||||||
sentLength = 0
|
|
||||||
while sentLength < len(networkPayload):
|
|
||||||
sent = sock.send(networkPayload[sentLength:])
|
|
||||||
if sent == 0:
|
|
||||||
raise RuntimeError("Socket connection broken.")
|
|
||||||
|
|
||||||
sentLength += sent
|
|
||||||
|
|
||||||
while len(sock.recv(1)) < 1:
|
while len(sock.recv(1)) < 1:
|
||||||
time.sleep(0.05)
|
time.sleep(0.05)
|
||||||
|
@ -80,7 +80,7 @@ static int remoteinstall_network_recvwait(int sockfd, void* buf, size_t len, int
|
|||||||
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
size_t read = 0;
|
size_t read = 0;
|
||||||
while(((ret = recv(sockfd, buf + read, len - read, flags)) >= 0 && (read += ret) < len) || errno == EAGAIN) {
|
while((((ret = recv(sockfd, buf + read, len - read, flags)) > 0 && (read += ret) < len) || errno == EAGAIN) && !(hidKeysDown() & KEY_B)) {
|
||||||
errno = 0;
|
errno = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ static int remoteinstall_network_sendwait(int sockfd, void* buf, size_t len, int
|
|||||||
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
size_t written = 0;
|
size_t written = 0;
|
||||||
while(((ret = send(sockfd, buf + written, len - written, flags)) >= 0 && (written += ret) < len) || errno == EAGAIN) {
|
while((((ret = send(sockfd, buf + written, len - written, flags)) > 0 && (written += ret) < len) || errno == EAGAIN) && !(hidKeysDown() & KEY_B)) {
|
||||||
errno = 0;
|
errno = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user