Unverified Commit c10536c1 authored by Sietse Ringers's avatar Sietse Ringers Committed by GitHub
Browse files

Merge pull request #9 from privacybydesign/sigpipe-transport

Sigpipe transport
parents c39104ea a0237cda
// +build ios
package disable_sigpipe
import (
"net"
"reflect"
"syscall"
)
// Taken from github.com/keybase/go-framed-msgpack-rpc/rpc/sigpipe_bsd.go
func DisableSigPipe(c net.Conn) error {
// Disable SIGPIPE on this connection since we currently need to do this manually for iOS
// to prevent the signal from crashing iOS apps.
// See: https://github.com/golang/go/issues/17393
netFD := reflect.ValueOf(c).Elem().FieldByName("fd").Elem()
sysfd := netFD.FieldByName("sysfd")
var fd int
if sysfd.IsValid() {
fd = int(sysfd.Int())
} else { // After go +3792db5
fd = int(netFD.FieldByName("pfd").FieldByName("Sysfd").Int())
}
return syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_NOSIGPIPE, 1)
}
\ No newline at end of file
// +build !ios
package disable_sigpipe
import "net"
func DisableSigPipe(c net.Conn) error {
return nil
}
\ No newline at end of file
......@@ -6,11 +6,13 @@ import (
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"path/filepath"
"strings"
"time"
"github.com/privacybydesign/irmago/internal/disable_sigpipe"
"github.com/privacybydesign/irmago/internal/fs"
)
......@@ -29,11 +31,27 @@ func NewHTTPTransport(serverURL string) *HTTPTransport {
if serverURL != "" && !strings.HasSuffix(url, "/") { // TODO fix this
url += "/"
}
// Create a transport that dials with a SIGPIPE handler (which is only active on iOS)
var innerTransport http.Transport
innerTransport.Dial = func(network, addr string) (c net.Conn, err error) {
c, err = net.Dial(network, addr)
if err != nil {
return c, err
}
if err = disable_sigpipe.DisableSigPipe(c); err != nil {
return c, err
}
return c, nil
}
return &HTTPTransport{
Server: url,
headers: map[string]string{},
client: &http.Client{
Timeout: time.Second * 15,
Timeout: time.Second * 15,
Transport: &innerTransport,
},
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment