[Spice-devel] [PATCH spice-server 23/30] Propagate some variable
Frediano Ziglio
fziglio at redhat.com
Mon Nov 21 12:52:10 UTC 2016
These were introduced moving code around
---
server/websocket.c | 47 ++++++++++++++++++++---------------------------
1 file changed, 20 insertions(+), 27 deletions(-)
diff --git a/server/websocket.c b/server/websocket.c
index 09d72c8..30e487e 100644
--- a/server/websocket.c
+++ b/server/websocket.c
@@ -79,7 +79,7 @@ struct RedsWebSocket {
websocket_writev_cb_t raw_writev;
};
-static void websocket_ack_close(void *opaque, websocket_write_cb_t write_cb);
+static void websocket_ack_close(void *stream, websocket_write_cb_t write_cb);
/* Perform a case insensitive search for needle in haystack.
If found, return a pointer to the byte after the end of needle.
@@ -249,9 +249,6 @@ int websocket_read(RedsWebSocket *ws, guchar *buf, size_t size)
int n = 0;
int rc;
websocket_frame_t *frame = &ws->read_frame;
- void *opaque = ws->raw_stream;
- websocket_read_cb_t read_cb = (websocket_read_cb_t) ws->raw_read;
- websocket_write_cb_t write_cb = (websocket_write_cb_t) ws->raw_write;
if (ws->closed) {
return 0;
@@ -259,7 +256,8 @@ int websocket_read(RedsWebSocket *ws, guchar *buf, size_t size)
while (size > 0) {
if (!frame->frame_ready) {
- rc = read_cb(ws->raw_stream, frame->header + frame->header_pos, frame_bytes_needed(frame));
+ rc = ws->raw_read(ws->raw_stream, frame->header + frame->header_pos,
+ frame_bytes_needed(frame));
if (rc <= 0) {
goto read_error;
}
@@ -267,12 +265,13 @@ int websocket_read(RedsWebSocket *ws, guchar *buf, size_t size)
websocket_get_frame_header(frame);
} else if (frame->type == CLOSE_FRAME) {
- websocket_ack_close(opaque, write_cb);
+ websocket_ack_close(ws->raw_stream, ws->raw_write);
websocket_clear_frame(frame);
ws->closed = TRUE;
return 0;
} else if (frame->type == BINARY_FRAME) {
- rc = read_cb(opaque, buf, MIN(size, frame->expected_len - frame->relayed));
+ rc = ws->raw_read(ws->raw_stream, buf,
+ MIN(size, frame->expected_len - frame->relayed));
if (rc <= 0) {
goto read_error;
}
@@ -370,24 +369,21 @@ int websocket_writev(RedsWebSocket *ws, const struct iovec *iov, int iovcnt)
int iov_out_cnt;
int i;
int header_len;
- void *opaque = ws->raw_stream;
- websocket_writev_cb_t writev_cb = (websocket_writev_cb_t) ws->raw_writev;
- guint64 *remainder = &ws->write_remainder;
if (ws->closed) {
errno = EPIPE;
return -1;
}
- if (*remainder > 0) {
- constrain_iov((struct iovec *) iov, iovcnt, &iov_out, &iov_out_cnt, *remainder);
- rc = writev_cb(opaque, iov_out, iov_out_cnt);
+ if (ws->write_remainder > 0) {
+ constrain_iov((struct iovec *) iov, iovcnt, &iov_out, &iov_out_cnt, ws->write_remainder);
+ rc = ws->raw_writev(ws->raw_stream, iov_out, iov_out_cnt);
if (iov_out != iov) {
free(iov_out);
}
if (rc <= 0) {
return rc;
}
- *remainder -= rc;
+ ws->write_remainder -= rc;
return rc;
}
@@ -403,7 +399,7 @@ int websocket_writev(RedsWebSocket *ws, const struct iovec *iov, int iovcnt)
header_len = fill_header(header, len);
iov_out[0].iov_len = header_len;
iov_out[0].iov_base = header;
- rc = writev_cb(opaque, iov_out, iov_out_cnt);
+ rc = ws->raw_writev(ws->raw_stream, iov_out, iov_out_cnt);
free(iov_out);
if (rc <= 0) {
return rc;
@@ -415,7 +411,7 @@ int websocket_writev(RedsWebSocket *ws, const struct iovec *iov, int iovcnt)
/* Key point: if we did not write out all the data, remember how
much more data the client is expecting, and write that data without
a header of any kind the next time around */
- *remainder = len - rc;
+ ws->write_remainder = len - rc;
return rc;
}
@@ -425,18 +421,15 @@ int websocket_write(RedsWebSocket *ws, const void *buf, size_t len)
guint8 header[WEBSOCKET_MAX_HEADER_SIZE];
int rc;
int header_len;
- void *opaque = ws->raw_stream;
- websocket_write_cb_t write_cb = (websocket_write_cb_t) ws->raw_write;
- guint64 *remainder = &ws->write_remainder;
if (ws->closed) {
errno = EPIPE;
return -1;
}
- if (*remainder == 0) {
+ if (ws->write_remainder == 0) {
header_len = fill_header(header, len);
- rc = write_cb(opaque, header, header_len);
+ rc = ws->raw_write(ws->raw_stream, header, header_len);
if (rc <= 0) {
return rc;
}
@@ -448,26 +441,26 @@ int websocket_write(RedsWebSocket *ws, const void *buf, size_t len)
return -1;
}
} else {
- len = MIN(*remainder, len);
+ len = MIN(ws->write_remainder, len);
}
- rc = write_cb(opaque, buf, len);
+ rc = ws->raw_write(ws->raw_stream, buf, len);
if (rc <= 0) {
- *remainder = len;
+ ws->write_remainder = len;
} else {
- *remainder = len - rc;
+ ws->write_remainder = len - rc;
}
return rc;
}
-static void websocket_ack_close(void *opaque, websocket_write_cb_t write_cb)
+static void websocket_ack_close(void *stream, websocket_write_cb_t write_cb)
{
unsigned char header[2];
header[0] = FIN_FLAG | CLOSE_FRAME;
header[1] = 0;
- write_cb(opaque, header, sizeof(header));
+ write_cb(stream, header, sizeof(header));
}
static bool websocket_is_start(gchar *buf)
--
2.7.4
More information about the Spice-devel
mailing list