Simplify sending of URLs in servefile, make socket operations cancellable by the user.

This commit is contained in:
Steveice10 2016-12-24 10:29:49 -08:00
parent 9182ebfa00
commit 22b26c2f34
2 changed files with 4 additions and 15 deletions

View File

@ -67,20 +67,9 @@ try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
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
sentLength = 0
while sentLength < len(networkPayload):
sent = sock.send(networkPayload[sentLength:])
if sent == 0:
raise RuntimeError("Socket connection broken.")
sentLength += sent
sock.sendall(struct.pack('!L', len(payloadBytes)) + payloadBytes)
while len(sock.recv(1)) < 1:
time.sleep(0.05)

View File

@ -80,7 +80,7 @@ static int remoteinstall_network_recvwait(int sockfd, void* buf, size_t len, int
int ret = 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;
}
@ -92,7 +92,7 @@ static int remoteinstall_network_sendwait(int sockfd, void* buf, size_t len, int
int ret = 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;
}