summaryrefslogtreecommitdiffstats
path: root/src/vcl
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2018-12-27 14:51:46 -0800
committerDave Barach <openvpp@barachs.net>2019-01-01 14:55:53 +0000
commitb0f662fe93f1db0098f7b50306c2f084644788b1 (patch)
treee70b7c9594391185c0c0b65f492a5ba931c4e69b /src/vcl
parent22af447454cf097ac4fc59f9072d805c371ab803 (diff)
vcl/ldp: add write msg function and fine tuning
Allows app to push data. Additionally, ensure reset/close replies are not sent unless vcl closes the session. Change-Id: Icbbf933cf57b55cfbcc7b802af0f83919a066f65 Signed-off-by: Florin Coras <fcoras@cisco.com>
Diffstat (limited to 'src/vcl')
-rw-r--r--src/vcl/ldp.c52
-rw-r--r--src/vcl/vppcom.c41
-rw-r--r--src/vcl/vppcom.h2
3 files changed, 30 insertions, 65 deletions
diff --git a/src/vcl/ldp.c b/src/vcl/ldp.c
index d538770eadb..0d4fe43dd7d 100644
--- a/src/vcl/ldp.c
+++ b/src/vcl/ldp.c
@@ -391,7 +391,7 @@ close (int fd)
errno = -rv;
rv = -1;
}
- if (refcnt == 1)
+ if (refcnt <= 1)
ldp_fd_free_w_sid (sid);
}
else
@@ -511,7 +511,7 @@ write (int fd, const void *buf, size_t nbytes)
LDBG (2, "fd %d (0x%x): calling vppcom_session_write(): sid %u (0x%x), "
"buf %p, nbytes %u", fd, fd, sid, sid, buf, nbytes);
- size = vppcom_session_write (sid, (void *) buf, nbytes);
+ size = vppcom_session_write_msg (sid, (void *) buf, nbytes);
if (size < 0)
{
errno = -size;
@@ -533,7 +533,6 @@ write (int fd, const void *buf, size_t nbytes)
ssize_t
writev (int fd, const struct iovec * iov, int iovcnt)
{
- const char *func_str;
ssize_t size = 0, total = 0;
u32 sid = ldp_sid_from_fd (fd);
int i, rv = 0;
@@ -547,33 +546,19 @@ writev (int fd, const struct iovec * iov, int iovcnt)
if (sid != INVALID_SESSION_ID)
{
- func_str = "vppcom_session_write";
do
{
for (i = 0; i < iovcnt; ++i)
{
- if (LDP_DEBUG > 4)
- printf ("%s:%d: LDP<%d>: fd %d (0x%x): calling %s() [%d]: "
- "sid %u (0x%x), buf %p, nbytes %ld, total %ld",
- __func__, __LINE__, getpid (), fd, fd, func_str,
- i, sid, sid, iov[i].iov_base, iov[i].iov_len, total);
-
- rv = vppcom_session_write (sid, iov[i].iov_base,
- iov[i].iov_len);
+ rv = vppcom_session_write_msg (sid, iov[i].iov_base,
+ iov[i].iov_len);
if (rv < 0)
break;
else
{
total += rv;
if (rv < iov[i].iov_len)
- {
- if (LDP_DEBUG > 4)
- printf ("%s:%d: LDP<%d>: fd %d (0x%x): "
- "rv (%d) < iov[%d].iov_len (%ld)",
- __func__, __LINE__, getpid (), fd, fd,
- rv, i, iov[i].iov_len);
- break;
- }
+ break;
}
}
}
@@ -589,32 +574,9 @@ writev (int fd, const struct iovec * iov, int iovcnt)
}
else
{
- func_str = "libc_writev";
-
- if (LDP_DEBUG > 4)
- printf ("%s:%d: LDP<%d>: fd %d (0x%x): calling %s(): "
- "iov %p, iovcnt %d\n", __func__, __LINE__, getpid (),
- fd, fd, func_str, iov, iovcnt);
-
size = libc_writev (fd, iov, iovcnt);
}
- if (LDP_DEBUG > 4)
- {
- if (size < 0)
- {
- int errno_val = errno;
- perror (func_str);
- fprintf (stderr,
- "%s:%d: LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
- "rv %ld, errno = %d\n", __func__, __LINE__, getpid (), fd,
- fd, func_str, size, errno_val);
- errno = errno_val;
- }
- else
- printf ("%s:%d: LDP<%d>: fd %d (0x%x): returning %ld\n",
- __func__, __LINE__, getpid (), fd, fd, size);
- }
return size;
}
@@ -3077,7 +3039,7 @@ ldp_epoll_pwait (int epfd, struct epoll_event *events, int maxevents,
return -1;
}
- time_to_wait = ((timeout >= 0) ? (double) timeout : 0);
+ time_to_wait = ((timeout >= 0) ? (double) timeout / 1000 : 0);
time_out = clib_time_now (&ldpw->clib_time) + time_to_wait;
func_str = "vppcom_session_attr[GET_LIBC_EPFD]";
@@ -3128,7 +3090,7 @@ ldp_epoll_pwait (int epfd, struct epoll_event *events, int maxevents,
epfd, epfd, func_str, libc_epfd, libc_epfd, events,
maxevents, sigmask);
- rv = libc_epoll_pwait (libc_epfd, events, maxevents, 1, sigmask);
+ rv = libc_epoll_pwait (libc_epfd, events, maxevents, 0, sigmask);
if (rv != 0)
goto done;
}
diff --git a/src/vcl/vppcom.c b/src/vcl/vppcom.c
index 86bb21413a4..a94df846402 100644
--- a/src/vcl/vppcom.c
+++ b/src/vcl/vppcom.c
@@ -410,7 +410,7 @@ vcl_flag_accepted_session (vcl_session_t * session, u64 handle, u32 flags)
accepted_msg = &session->accept_evts_fifo[i];
if (accepted_msg->accepted_msg.handle == handle)
{
- accepted_msg->flags = flags;
+ accepted_msg->flags |= flags;
return 1;
}
}
@@ -431,8 +431,6 @@ vcl_session_reset_handler (vcl_worker_t * wrk,
VDBG (0, "request to reset unknown handle 0x%llx", reset_msg->handle);
return VCL_INVALID_SESSION_INDEX;
}
- if (session->session_state >= STATE_VPP_CLOSING)
- return sid;
/* Caught a reset before actually accepting the session */
if (session->session_state == STATE_LISTEN)
@@ -446,8 +444,6 @@ vcl_session_reset_handler (vcl_worker_t * wrk,
session->session_state = STATE_DISCONNECT;
VDBG (0, "reset session %u [0x%llx]", sid, reset_msg->handle);
- vcl_send_session_reset_reply (vcl_session_vpp_evt_q (wrk, session),
- wrk->my_client_index, reset_msg->handle, 0);
return sid;
}
@@ -509,7 +505,8 @@ vcl_session_accepted (vcl_worker_t * wrk, session_accepted_msg_t * msg)
session = vcl_session_get_w_vpp_handle (wrk, msg->handle);
if (PREDICT_FALSE (session != 0))
- VWRN ("session handle overlap %lu!", msg->handle);
+ VWRN ("session overlap handle %lu state %u!", msg->handle,
+ session->session_state);
session = vcl_session_table_lookup_listener (wrk, msg->listener_handle);
if (!session)
@@ -1119,6 +1116,12 @@ vppcom_session_close (uint32_t session_handle)
getpid (), vpp_handle, session_handle,
rv, vppcom_retval_str (rv));
}
+ else if (state == STATE_DISCONNECT)
+ {
+ svm_msg_q_t *mq = vcl_session_vpp_evt_q (wrk, session);
+ vcl_send_session_reset_reply (mq, wrk->my_client_index,
+ session->vpp_handle, 0);
+ }
}
cleanup:
@@ -1378,19 +1381,10 @@ handle:
*/
if (accept_flags)
{
- svm_msg_q_t *mq = vcl_session_vpp_evt_q (wrk, client_session);
if (accept_flags & VCL_ACCEPTED_F_CLOSED)
- {
- client_session->session_state = STATE_DISCONNECT;
- vcl_send_session_disconnected_reply (mq, wrk->my_client_index,
- client_session->vpp_handle, 0);
- }
+ client_session->session_state = STATE_VPP_CLOSING;
else if (accept_flags & VCL_ACCEPTED_F_RESET)
- {
- client_session->session_state = STATE_DISCONNECT;
- vcl_send_session_reset_reply (mq, wrk->my_client_index,
- client_session->vpp_handle, 0);
- }
+ client_session->session_state = STATE_DISCONNECT;
}
return vcl_session_handle (client_session);
}
@@ -1524,9 +1518,8 @@ vppcom_session_read_internal (uint32_t session_handle, void *buf, int n,
session_state_t state = s->session_state;
rv = ((state & STATE_DISCONNECT) ? VPPCOM_ECONNRESET : VPPCOM_ENOTCONN);
- VDBG (0, "VCL<%d>: vpp handle 0x%llx, sid %u: %s session is not open! "
- "state 0x%x (%s), returning %d (%s)",
- getpid (), s->vpp_handle, session_handle, state,
+ VDBG (0, "session handle %u[0x%llx] is not open! state 0x%x (%s),"
+ " returning %d (%s)", session_handle, s->vpp_handle, state,
vppcom_session_state_str (state), rv, vppcom_retval_str (rv));
return rv;
}
@@ -1831,6 +1824,14 @@ vppcom_session_write (uint32_t session_handle, void *buf, size_t n)
0 /* is_flush */ );
}
+int
+vppcom_session_write_msg (uint32_t session_handle, void *buf, size_t n)
+{
+ return vppcom_session_write_inline (session_handle, buf, n,
+ 1 /* is_flush */ );
+}
+
+
static vcl_session_t *
vcl_ct_session_get_from_fifo (vcl_worker_t * wrk, svm_fifo_t * f, u8 type)
{
diff --git a/src/vcl/vppcom.h b/src/vcl/vppcom.h
index 30ab7c4a56a..00527f4ecfb 100644
--- a/src/vcl/vppcom.h
+++ b/src/vcl/vppcom.h
@@ -239,6 +239,8 @@ extern int vppcom_session_connect (uint32_t session_handle,
extern int vppcom_session_read (uint32_t session_handle, void *buf, size_t n);
extern int vppcom_session_write (uint32_t session_handle, void *buf,
size_t n);
+extern int vppcom_session_write_msg (uint32_t session_handle, void *buf,
+ size_t n);
extern int vppcom_select (unsigned long n_bits,
unsigned long *read_map,