Code Review
/
src
/
app-framework-binder.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
api-dbus: improves 'dbus_req_json'
[src/app-framework-binder.git]
/
src
/
afb-ws-client.c
diff --git
a/src/afb-ws-client.c
b/src/afb-ws-client.c
index
2569d13
..
0faa60f
100644
(file)
--- a/
src/afb-ws-client.c
+++ b/
src/afb-ws-client.c
@@
-26,6
+26,7
@@
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
+#include <fcntl.h>
#include "afb-wsj1.h"
#include "afb-wsj1.h"
@@
-110,7
+111,7
@@
static char *strjoin(int count, const char **strings, const char *separ)
/* creates the http message for the request */
static int make_request(char **request, const char *path, const char *host, const char *key, const char *protocols)
{
/* creates the http message for the request */
static int make_request(char **request, const char *path, const char *host, const char *key, const char *protocols)
{
- int rc = asprintf(request,
+ int rc = asprintf(request,
"GET %s HTTP/1.1\r\n"
"Host: %s\r\n"
"Upgrade: websocket\r\n"
"GET %s HTTP/1.1\r\n"
"Host: %s\r\n"
"Upgrade: websocket\r\n"
@@
-200,15
+201,15
@@
static int receive_response(int fd, const char **protocols, const char *ack)
goto error;
len = strcspn(line, " ");
if (len != 8 || 0 != strncmp(line, "HTTP/1.1", 8))
goto error;
len = strcspn(line, " ");
if (len != 8 || 0 != strncmp(line, "HTTP/1.1", 8))
- goto
error
;
+ goto
abort
;
it = line + len;
len = strspn(it, " ");
if (len == 0)
it = line + len;
len = strspn(it, " ");
if (len == 0)
- goto
error
;
+ goto
abort
;
it += len;
len = strcspn(it, " ");
if (len != 3 || 0 != strncmp(it, "101", 3))
it += len;
len = strcspn(it, " ");
if (len != 3 || 0 != strncmp(it, "101", 3))
- goto
error
;
+ goto
abort
;
/* reads the rest of the response until empty line */
clen = 0;
/* reads the rest of the response until empty line */
clen = 0;
@@
-249,15
+250,13
@@
static int receive_response(int fd, const char **protocols, const char *ack)
if (clen > 0) {
while (read(fd, line, len) < 0 && errno == EINTR);
}
if (clen > 0) {
while (read(fd, line, len) < 0 && errno == EINTR);
}
- if (haserr != 0)
- result = -1;
- else if (result < 0) {
- result = 0;
- while(protocols[result] != NULL)
- result++;
- }
-error:
+ if (haserr != 0 || result < 0)
+ goto abort;
return result;
return result;
+abort:
+ errno = ECONNABORTED;
+error:
+ return -1;
}
static int negociate(int fd, const char **protocols, const char *path, const char *host)
}
static int negociate(int fd, const char **protocols, const char *path, const char *host)
@@
-315,7
+314,6
@@
invalid:
errno = EINVAL;
error:
return -1;
errno = EINVAL;
error:
return -1;
-
}
}
@@
-323,7
+321,7
@@
error:
static const char *proto_json1[2] = { "x-afb-ws-json1", NULL };
static const char *proto_json1[2] = { "x-afb-ws-json1", NULL };
-struct afb_wsj1 *afb_ws_client_connect_wsj1(const char *uri, struct afb_wsj1_itf *itf, void *closure)
+struct afb_wsj1 *afb_ws_client_connect_wsj1(
struct sd_event *eloop,
const char *uri, struct afb_wsj1_itf *itf, void *closure)
{
int rc, fd;
char *host, *service, xhost[32];
{
int rc, fd;
char *host, *service, xhost[32];
@@
-364,9
+362,11
@@
struct afb_wsj1 *afb_ws_client_connect_wsj1(const char *uri, struct afb_wsj1_itf
if (rc == 0) {
rc = negociate(fd, proto_json1, path, xhost);
if (rc == 0) {
if (rc == 0) {
rc = negociate(fd, proto_json1, path, xhost);
if (rc == 0) {
- result = afb_wsj1_create(fd, itf, closure);
- if (result != NULL)
+ result = afb_wsj1_create(eloop, fd, itf, closure);
+ if (result != NULL) {
+ fcntl(fd, F_SETFL, O_NONBLOCK);
break;
break;
+ }
}
}
close(fd);
}
}
close(fd);