MEDIUM: stream-interface: provide a generic si_conn_send_cb callback

The connection send() callback is supposed to be generic for a
stream-interface, and consists in calling the lower layer snd_buf
function. Move this function to the stream interface and remove
the sock-raw and sock-ssl clones.
This commit is contained in:
Willy Tarreau 2012-08-20 15:09:53 +02:00 committed by Willy Tarreau
parent de5722c302
commit eecf6ca68a
3 changed files with 36 additions and 34 deletions

View File

@ -41,6 +41,7 @@ int stream_int_shutr(struct stream_interface *si);
int stream_int_shutw(struct stream_interface *si);
void stream_int_chk_rcv_conn(struct stream_interface *si);
void stream_int_chk_snd_conn(struct stream_interface *si);
void si_conn_send_cb(struct connection *conn);
extern struct sock_ops stream_int_embedded;
extern struct sock_ops stream_int_task;

View File

@ -44,7 +44,6 @@
/* main event functions used to move data between sockets and buffers */
static void sock_raw_read(struct connection *conn);
static void sock_raw_write(struct connection *conn);
static void sock_raw_read0(struct stream_interface *si);
@ -592,38 +591,6 @@ static int sock_raw_write_loop(struct connection *conn)
}
/*
* This function is called on a write event from a stream socket.
*/
static void sock_raw_write(struct connection *conn)
{
struct stream_interface *si = container_of(conn, struct stream_interface, conn);
struct buffer *b = si->ob;
#ifdef DEBUG_FULL
fprintf(stderr,"sock_raw_write : fd=%d, owner=%p\n", fd, fdtab[fd].owner);
#endif
if (conn->flags & CO_FL_ERROR)
goto out_error;
/* we might have been called just after an asynchronous shutw */
if (b->flags & BF_SHUTW)
return;
if (conn_data_snd_buf(conn) < 0)
goto out_error;
/* OK all done */
return;
out_error:
/* Write error on the connection, report the error and stop I/O */
conn->flags |= CO_FL_ERROR;
conn_data_stop_both(conn);
}
/*
* This function propagates a null read received on a connection. It updates
* the stream interface. If the stream interface has SI_FL_NOHALF, we also
@ -681,7 +648,7 @@ struct sock_ops sock_raw = {
.chk_rcv = stream_int_chk_rcv_conn,
.chk_snd = stream_int_chk_snd_conn,
.read = sock_raw_read,
.write = sock_raw_write,
.write = si_conn_send_cb,
.snd_buf = sock_raw_write_loop,
.close = NULL,
};

View File

@ -864,6 +864,40 @@ void stream_int_chk_snd_conn(struct stream_interface *si)
}
}
/*
* This is the callback which is called by the connection layer to send data
* from the buffer to the connection. It iterates over the data layer's snd_buf
* function.
*/
void si_conn_send_cb(struct connection *conn)
{
struct stream_interface *si = container_of(conn, struct stream_interface, conn);
struct buffer *b = si->ob;
if (conn->flags & CO_FL_ERROR)
goto out_error;
if (si->conn.flags & CO_FL_HANDSHAKE)
/* a handshake was requested */
return;
/* we might have been called just after an asynchronous shutw */
if (b->flags & BF_SHUTW)
return;
/* OK there are data waiting to be sent */
if (conn_data_snd_buf(conn) < 0)
goto out_error;
/* OK all done */
return;
out_error:
/* Write error on the connection, report the error and stop I/O */
conn->flags |= CO_FL_ERROR;
conn_data_stop_both(conn);
}
/*
* Local variables: