Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
IRMA
Github mirrors
irmago
Commits
c10536c1
Unverified
Commit
c10536c1
authored
Feb 24, 2018
by
Sietse Ringers
Committed by
GitHub
Feb 24, 2018
Browse files
Merge pull request #9 from privacybydesign/sigpipe-transport
Sigpipe transport
parents
c39104ea
a0237cda
Changes
3
Hide whitespace changes
Inline
Side-by-side
internal/disable_sigpipe/disable_sigpipe.go
0 → 100644
View file @
c10536c1
// +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
internal/disable_sigpipe/noop.go
0 → 100644
View file @
c10536c1
// +build !ios
package
disable_sigpipe
import
"net"
func
DisableSigPipe
(
c
net
.
Conn
)
error
{
return
nil
}
\ No newline at end of file
transport.go
View file @
c10536c1
...
...
@@ -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
,
},
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment