From 0d2b0d5497b61afb5c964373c7bed974d78762a0 Mon Sep 17 00:00:00 2001 From: "Keith Burns (alagalah)" Date: Tue, 6 Mar 2018 15:55:22 -0800 Subject: VCL API for external callback for listener/connect event Change-Id: Ic59355683b581945d10a2df97d9b2deae87a998e Signed-off-by: Keith Burns (alagalah) --- src/vcl/test_vcl_listener_server.c | 102 +++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 src/vcl/test_vcl_listener_server.c (limited to 'src/vcl/test_vcl_listener_server.c') diff --git a/src/vcl/test_vcl_listener_server.c b/src/vcl/test_vcl_listener_server.c new file mode 100644 index 00000000000..bebef250f22 --- /dev/null +++ b/src/vcl/test_vcl_listener_server.c @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2018 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include +#include +#include +#include +#include +#include + + +#include +#include + +char MESSAGE[] = "Hello, World!\n"; + +static const int PORT = 9995; + +void +listener_cb (uint32_t new_session_index, vppcom_endpt_t *ep, void *stuff) +{ + + vppcom_session_write (new_session_index, &MESSAGE, sizeof (MESSAGE)); + printf ("\n Heard from port: %d\n", ep->port); +} + + +typedef struct vppcomm_listener_main_ +{ + int new_fd; + + struct event *event; + +} vppcomm_listener_main_t; + +vppcomm_listener_main_t _vlm_main; +vppcomm_listener_main_t *vlm = &_vlm_main; + + +int +main (int argc, char **argv) +{ + + int rv; + struct sockaddr_in sin; + uint32_t listen_fd; + vppcom_endpt_t endpt; + + //Address stuff + memset (&sin, 0, sizeof (sin)); + sin.sin_family = AF_INET; + sin.sin_port = htons (PORT); + //sin.sin_addr.s_addr = inet_addr("127.0.0.1"); + + endpt.is_ip4 = (sin.sin_family == AF_INET); + endpt.ip = (uint8_t *) & sin.sin_addr; + endpt.port = (uint16_t) sin.sin_port; + + //VCL stuff + rv = vppcom_app_create ("test_vcl_listener_server"); + if (rv) return rv; + + listen_fd = vppcom_session_create (VPPCOM_PROTO_TCP, + 0 /* is_nonblocking */ ); + + rv = vppcom_session_bind (listen_fd, &endpt); + + //Make a listener and dispatch + rv = vppcom_session_register_listener (listen_fd, listener_cb, 0, + 0, 0, &MESSAGE); + + if (rv) + { + fprintf (stderr, "Could not create a listener!\n"); + return 1; + } + + while (1) + { + sleep (3); + } + + printf ("done\n"); + return 0; +} + + -- cgit 1.2.3-korg