[Spice-devel] [PATCH spice-server 04/30] Some style changes
Frediano Ziglio
fziglio at redhat.com
Mon Nov 21 12:51:51 UTC 2016
---
server/websocket.c | 21 ++++++++-------------
server/websocket.h | 3 +--
2 files changed, 9 insertions(+), 15 deletions(-)
diff --git a/server/websocket.c b/server/websocket.c
index cfd93a0..0f433f0 100644
--- a/server/websocket.c
+++ b/server/websocket.c
@@ -16,6 +16,7 @@
License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#define _GNU_SOURCE
+#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
@@ -234,13 +235,11 @@ int websocket_read(void *opaque, guchar *buf, int size, websocket_frame_t *frame
frame->header_pos += rc;
websocket_get_frame_header(frame);
- }
- else if (frame->type == CLOSE_FRAME) {
+ } else if (frame->type == CLOSE_FRAME) {
websocket_ack_close(opaque, write_cb);
websocket_clear_frame(frame);
return 0;
- }
- else if (frame->type == BINARY_FRAME) {
+ } else if (frame->type == BINARY_FRAME) {
rc = read_cb(opaque, buf, MIN(size, frame->expected_len - frame->relayed));
if (rc <= 0) {
if (n > 0 && rc == -1 && (errno == EINTR || errno == EAGAIN))
@@ -256,8 +255,7 @@ int websocket_read(void *opaque, guchar *buf, int size, websocket_frame_t *frame
if (frame->relayed >= frame->expected_len)
websocket_clear_frame(frame);
- }
- else {
+ } else {
/* TODO - We don't handle PING at this point */
spice_warning("Unexpected WebSocket frame.type %d. Failure now likely.", frame->type);
websocket_clear_frame(frame);
@@ -294,10 +292,9 @@ static int fill_header(guint8 *header, guint64 len)
header[2] = len >> 8;
header[3] = len & 0xFF;
used += 2;
- }
-
- else
+ } else {
header[1] |= len;
+ }
return used;
}
@@ -315,7 +312,7 @@ static void constrain_iov(struct iovec *iov, int iovcnt,
if (iov[i].iov_len > maxlen) {
/* TODO - This code has never triggered afaik... */
*iov_out_cnt = i + 1;
- *iov_out = malloc((*iov_out_cnt) * sizeof (**iov_out));
+ *iov_out = spice_malloc((*iov_out_cnt) * sizeof (**iov_out));
for (j = 0; j < i; j++) {
(*iov_out)[j].iov_base = iov[j].iov_base;
(*iov_out)[j].iov_len = iov[j].iov_len;
@@ -355,9 +352,7 @@ int websocket_writev(void *opaque, struct iovec *iov, int iovcnt, guint64 *remai
}
iov_out_cnt = iovcnt + 1;
- iov_out = malloc(iov_out_cnt * sizeof(*iov_out));
- if (! iov_out)
- return -1;
+ iov_out = spice_malloc(iov_out_cnt * sizeof(*iov_out));
for (i = 0, len = 0; i < iovcnt; i++) {
len += iov[i].iov_len;
diff --git a/server/websocket.h b/server/websocket.h
index 02aacc1..2306492 100644
--- a/server/websocket.h
+++ b/server/websocket.h
@@ -17,8 +17,7 @@
#define WEBSOCKET_MAX_HEADER_SIZE (1 + 9 + 4)
-typedef struct
-{
+typedef struct {
int type;
int masked;
guint8 header[WEBSOCKET_MAX_HEADER_SIZE];
--
2.7.4
More information about the Spice-devel
mailing list