Pass the wqueue directly to the wqueue callback functions
This commit is contained in:
@@ -24,6 +24,8 @@ enum UC_WQ_RESULT {
|
||||
UC_WQ_ABORT = -1
|
||||
};
|
||||
|
||||
struct UCWQueue;
|
||||
|
||||
/**
|
||||
* Callback that will be called when data can be written to the fd.
|
||||
* The return value from this function must be strictly followed.
|
||||
@@ -49,7 +51,9 @@ enum UC_WQ_RESULT {
|
||||
* for this event.
|
||||
*
|
||||
*/
|
||||
typedef enum UC_WQ_RESULT (*wqueue_write_cb)(struct IOMux *mux, struct IOMuxFD *fd, struct MBuf *mbuf);
|
||||
typedef enum UC_WQ_RESULT (*wqueue_write_cb)(struct IOMux *mux,
|
||||
struct UCWQueue *wqueue,
|
||||
struct MBuf *mbuf);
|
||||
|
||||
/**
|
||||
* Callback when read events are indicated.
|
||||
@@ -60,7 +64,8 @@ typedef enum UC_WQ_RESULT (*wqueue_write_cb)(struct IOMux *mux, struct IOMuxFD *
|
||||
* @param mux associated IOMux
|
||||
* @param the fd of the current wqueue
|
||||
*/
|
||||
typedef enum UC_WQ_RESULT (*wqueue_read_cb)(struct IOMux *mux, struct IOMuxFD *fd);
|
||||
typedef enum UC_WQ_RESULT (*wqueue_read_cb)(struct IOMux *mux,
|
||||
struct UCWQueue *wqueue);
|
||||
|
||||
/**
|
||||
* Represents a queue of data to write.
|
||||
|
||||
+2
-2
@@ -15,7 +15,7 @@ static int uc_wqueue_handle_write(struct UCWQueue *wqueue)
|
||||
q = UC_TAILQ_FIRST(&wqueue->queue);
|
||||
|
||||
mbuf = UC_TAILQ_CONTAINER(q, struct MBuf, entry);
|
||||
rc = wqueue->write_cb(mux, fd, mbuf);
|
||||
rc = wqueue->write_cb(mux, wqueue, mbuf);
|
||||
if (rc <= 0) {
|
||||
//NOTE for rc < 0, nothing can touch the wqueue or fd
|
||||
//any more, as it might been free'd
|
||||
@@ -58,7 +58,7 @@ static void uc_wqueue_cb(struct IOMux *mux, struct IOMuxFD *fd, unsigned int wha
|
||||
|
||||
|
||||
if (rc >= 0 && what & MUX_EV_READ) {
|
||||
rc = wqueue->read_cb(mux, fd);
|
||||
rc = wqueue->read_cb(mux, wqueue);
|
||||
//NOTE - can't touch the wqueue or fd after this point,
|
||||
//as it might been free'd
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <ucore/fd_utils.h>
|
||||
|
||||
|
||||
int stdout_read(struct IOMux *mux, struct IOMuxFD *fd)
|
||||
int stdout_read(struct IOMux *mux, struct UCWQueue *wqueue)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
@@ -24,9 +24,9 @@ void stdin_read_cb(struct IOMux *mux, struct IOMuxFD *fd, unsigned int event)
|
||||
printf("Read %d bytes\n", len);
|
||||
if (len <= 0) {
|
||||
uc_mbuf_free(mbuf);
|
||||
iomux_unregister_fd(mux, fd);
|
||||
uc_wqueue_clear(wqueue);
|
||||
iomux_unregister_fd(mux, &wqueue->fd);
|
||||
uc_wqueue_clear(wqueue);
|
||||
iomux_unregister_fd(mux, fd);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -44,7 +44,7 @@ struct IOMuxFD stdin_fd = {
|
||||
|
||||
};
|
||||
|
||||
int stdout_write(struct IOMux *mux, struct IOMuxFD *fd, struct MBuf *mbuf)
|
||||
int stdout_write(struct IOMux *mux, struct UCWQueue *wqueue, struct MBuf *mbuf)
|
||||
{
|
||||
uint32_t len;
|
||||
ssize_t wlen;
|
||||
@@ -52,7 +52,7 @@ int stdout_write(struct IOMux *mux, struct IOMuxFD *fd, struct MBuf *mbuf)
|
||||
|
||||
len = uc_mbuf_len(mbuf);
|
||||
data = uc_mbuf_pull(mbuf, len);
|
||||
wlen = write(fd->fd, data, len);
|
||||
wlen = write(wqueue->fd.fd, data, len);
|
||||
|
||||
if (wlen < 0) {
|
||||
if (errno != EWOULDBLOCK) {
|
||||
|
||||
Reference in New Issue
Block a user