diff --git a/HTML5-frontend/script.js b/HTML5-frontend/script.js index 34e625b..abe8eff 100644 --- a/HTML5-frontend/script.js +++ b/HTML5-frontend/script.js @@ -23,6 +23,8 @@ var PHASE_RESULTS = 5; // STATUS VARIABLES +var use_websocket_client = false; + var websocket_client = null; var currentPhase = PHASE_LOADING; @@ -32,8 +34,7 @@ var transitionSpeed = 400; // Gauges used for showing download/upload speed var downloadGauge, uploadGauge; var gaugeUpdateInterval; -var gaugeMaxValue = 100; // Mb/s - +var gaugeMaxValue = 1000; // PRIMARY METHODS @@ -58,6 +59,7 @@ function initializeTest() { function startTest(evt) { evt.stopPropagation(); evt.preventDefault(); + createBackend(); if (!isPluginLoaded()) { $('#warning-plugin').show(); return; @@ -322,10 +324,19 @@ function resetGauges() { } function updateGaugeValue() { + var downloadSpeedVal = downloadSpeed(); + var uploadSpeedVal = uploadSpeed(false); + if (currentPhase == PHASE_UPLOAD) { - uploadGauge.setValue(uploadSpeed(true)); + uploadGauge.updateConfig({ + units: getSpeedUnit(uploadSpeedVal) + }); + uploadGauge.setValue(getJustfiedSpeed(uploadSpeedVal)); } else if (currentPhase == PHASE_DOWNLOAD) { - downloadGauge.setValue(downloadSpeed()); + downloadGauge.updateConfig({ + units: getSpeedUnit(downloadSpeedVal) + }); + downloadGauge.setValue(getJustfiedSpeed(downloadSpeedVal)); } else { clearInterval(gaugeUpdateInterval); } @@ -338,7 +349,7 @@ function testNDT() { return websocket_client; } - return ndt = document.getElementById('NDT'); + return document.getElementById('NDT'); } function testStatus() { @@ -445,28 +456,27 @@ function printJitter(boldValue) { return retStr; } +function getSpeedUnit(speedInKB) { + var unit = ['kb/s', 'Mb/s', 'Gb/s', 'Tb/s', 'Pb/s', 'Eb/s']; + var e = Math.floor(Math.log(speedInKB*1000) / Math.log(1000)); + return unit[e]; +} + +function getJustfiedSpeed(speedInKB) { + var e = Math.floor(Math.log(speedInKB) / Math.log(1000)); + return (speedInKB / Math.pow(1000, e)).toFixed(2); +} + function printDownloadSpeed() { var downloadSpeedVal = downloadSpeed(); - if (downloadSpeedVal >= 1000) { - downloadSpeedVal = parseFloat(downloadSpeedVal/1000); - document.getElementById('download-speed').innerHTML = downloadSpeedVal.toFixed(2); - document.getElementById('download-speed-units').innerHTML = 'gb/s'; - } else { - document.getElementById('download-speed').innerHTML = downloadSpeedVal.toFixed(2); - document.getElementById('download-speed-units').innerHTML = 'mb/s'; - } + document.getElementById('download-speed').innerHTML = getJustfiedSpeed(downloadSpeedVal); + document.getElementById('download-speed-units').innerHTML = getSpeedUnit(downloadSpeedVal); } function printUploadSpeed() { var uploadSpeedVal = uploadSpeed(false); - if (uploadSpeedVal >= 1000) { - uploadSpeedVal = parseFloat(uploadSpeedVal/1000); - document.getElementById('upload-speed').innerHTML = uploadSpeedVal.toFixed(2); - document.getElementById('upload-speed-units').innerHTML = 'gb/s'; - } else { - document.getElementById('upload-speed').innerHTML = uploadSpeedVal.toFixed(2); - document.getElementById('upload-speed-units').innerHTML = 'mb/s'; - } + document.getElementById('upload-speed').innerHTML = getJustfiedSpeed(uploadSpeedVal); + document.getElementById('upload-speed-units').innerHTML = getSpeedUnit(uploadSpeedVal); } function readNDTvar(variable) { @@ -549,25 +559,14 @@ function testDetails() { // BACKEND METHODS function useJavaAsBackend() { - websocket_client = null; - $('#warning-websocket').hide(); $("#rtt").show(); $("#rttValue").show(); - var backendContainer = document.getElementById('backendContainer'); - while (backendContainer.firstChild) { - backendContainer.removeChild(backendContainer.firstChild); - } - document.getElementById('warning-environment').innerHTML = ""; - - var app = document.createElement('applet'); - app.id = 'NDT'; - app.name = 'NDT'; - app.archive = 'Tcpbw100.jar'; - app.code = 'edu.internet2.ndt.Tcpbw100.class'; - app.width = '600'; - app.height = '10'; - document.getElementById('backendContainer').appendChild(app); + + $('.warning-environment').innerHTML = ""; + + use_websocket_client = false; + $('#websocketButton').removeClass("active"); $('#javaButton').addClass("active"); } @@ -577,17 +576,30 @@ function useWebsocketAsBackend() { $("#rttValue").hide(); $('#warning-websocket').show(); - var backendContainer = document.getElementById('backendContainer'); - while (backendContainer.firstChild) { - backendContainer.removeChild(backendContainer.firstChild); - } - - websocket_client = new NDTWrapper(); + use_websocket_client = true; $('#javaButton').removeClass("active"); $('#websocketButton').addClass("active"); } +function createBackend() { + $('#backendContainer').empty(); + + if (use_websocket_client) { + websocket_client = new NDTWrapper(); + } + else { + var app = document.createElement('applet'); + app.id = 'NDT'; + app.name = 'NDT'; + app.archive = 'Tcpbw100.jar'; + app.code = 'edu.internet2.ndt.Tcpbw100.class'; + app.width = '600'; + app.height = '10'; + $('#backendContainer').append(app); + } +} + // UTILITIES function debug(message) { diff --git a/conf/ndt-init b/conf/ndt-init index 46c50ce..c46a51b 100755 --- a/conf/ndt-init +++ b/conf/ndt-init @@ -60,7 +60,7 @@ then touch /var/log/ndt/fakewww_error.log chown nobody:nobody /var/log/ndt/fakewww*log - sudo -u nobody $path/fakewww $FAKEWWW_OPTIONS 2>/dev/null & + runuser --session-command="$path/fakewww $FAKEWWW_OPTIONS" -s /bin/sh nobody & RETVAL=$? if [ $RETVAL = 0 ] then @@ -133,8 +133,20 @@ restart() { } condrestart() { - rhstatus - if [ $? == 0 ]; then + RUNNING=0 + status web100srv + if [ $? -eq 0 ]; then + RUNNING=1 + fi + if [ ! $USE_FAKEWWW = 0 ] + then + status fakewww + if [ $? -eq 0 ]; then + RUNNING=1 + fi + fi + + if [ $RUNNING -eq 1 ]; then restart fi } @@ -149,14 +161,14 @@ stop) status) rhstatus ;; -cond-restart) +condrestart) condrestart ;; restart|reload) restart ;; *) - echo $"Usage: $0 {start|stop|status|restart}" + echo $"Usage: $0 {start|stop|status|restart|condrestart}" exit 1 esac diff --git a/configure.ac b/configure.ac index 9037931..57f81bf 100644 --- a/configure.ac +++ b/configure.ac @@ -29,7 +29,7 @@ # Process this file with autoconf to produce a configure script. # # AC_PREREQ(2.57) -AC_INIT([NDT],[3.7.0],[ndt-user@internet2.edu]) +AC_INIT([NDT],[3.7.0.1],[ndt-user@internet2.edu]) AC_CONFIG_AUX_DIR(config) # AM_INIT_AUTOMAKE(NDT, v1.0, [no-define]) AM_INIT_AUTOMAKE diff --git a/ndt.spec b/ndt.spec index 1eeae44..8e608bb 100644 --- a/ndt.spec +++ b/ndt.spec @@ -1,6 +1,6 @@ Name: ndt -Version: 3.7.0 -Release: 8%{?dist} +Version: 3.7.0.1 +Release: 2%{?dist} Summary: Network Diagnostic Tool Group: Applications/Networking @@ -92,7 +92,7 @@ if [ "$1" = "1" ]; then # If this is a first time install, add the users and enable it by default /sbin/chkconfig --add ndt else - /sbin/service ndt cond-restart + /sbin/service ndt condrestart fi %preun server @@ -103,9 +103,22 @@ fi %post server-apache %{_prefix}/%{name}/manage_fakewww_usage disable +# Need to restart NDT first so that it lets go of 7123 +service ndt condrestart +service httpd condrestart %preun server-apache -%{_prefix}/%{name}/manage_fakewww_usage enable +if [ $1 -eq 0 ]; then + # This will retry to start NDT, but since apache still has the port, + # it'll fail. The %postun condrestart will get NDT going again. + %{_prefix}/%{name}/manage_fakewww_usage enable || : +fi + +%postun server-apache +# Need to restart HTTPD first so that it lets go of 7123. This gets done in the +# '%postun' so that the apache ndt.conf is gone. +service httpd condrestart +service ndt condrestart %files diff --git a/src/Makefile.am b/src/Makefile.am index 5252d81..802ff45 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -47,6 +47,7 @@ endif endif endif + if HAVE_SSL if HAVE_JANSSON bin_PROGRAMS += web100clt @@ -78,7 +79,7 @@ endif noinst_PROGRAMS += $(TESTS) -web100clt_SOURCES = web100clt.c network.c network_clt.c usage.c logging.c utils.c protocol.c runningtest.c ndtptestconstants.c \ +web100clt_SOURCES = web100clt.c network.c usage.c logging.c utils.c protocol.c runningtest.c ndtptestconstants.c \ test_sfw_clt.c test_mid_clt.c test_c2s_clt.c test_s2c_clt.c test_meta_clt.c strlutils.c \ test_results_clt.c jsonutils.c websocket.c web100clt_LDADD = $(I2UTILLIBDEPS) -lpthread $(ZLIB) $(JSONLIB) $(OPENSSL_LDFLAGS) $(OPENSSL_LIBS) @@ -98,7 +99,7 @@ analyze_LDADD = $(NDTLIBS) $(I2UTILLIBDEPS) $(ZLIB) analyze_CPPFLAGS ='-DBASEDIR="$(ndtdir)"' -DFORCE_WEB100 if BUILD_FAKEWWW -fakewww_SOURCES = fakewww.c troute.c troute6.c tr-tree.c tr-tree6.c network.c network_clt.c usage.c logging.c \ +fakewww_SOURCES = fakewww.c troute.c troute6.c tr-tree.c tr-tree6.c network.c usage.c logging.c \ runningtest.c ndtptestconstants.c strlutils.c jsonutils.c websocket.c fakewww_LDADD = $(I2UTILLIBDEPS) $(ZLIB) $(JSONLIB) $(OPENSSL_LDFLAGS) $(OPENSSL_LIBS) fakewww_CPPFLAGS ='-DBASEDIR="$(ndtdir)"' $(OPENSSL_INCLUDES) @@ -189,9 +190,7 @@ install: install-am install-ln $(I2UTILLIBDEPS): $(I2UTILLIBMAKE) -EXTRA_DIST = clt_tests.h connection.h heuristics.h jsonutils.h logging.h \ - mrange.h ndt_odbc.h ndtptestconstants.h network.h network_clt.h \ - node_tests/ndt_client.js protocol.h runningtest.h strlutils.h test_meta.h \ - test_results_clt.h test_sfw.h testoptions.h tests_srv.h third_party/safe_iop.h \ - tr-tree.h troute.h unit_testing.h usage.h utils.h varinfo.h web100-admin.h \ - web100srv.h websocket.h +EXTRA_DIST = clt_tests.h logging.h mrange.h network.h protocol.h testoptions.h test_sfw.h test_meta.h \ + troute.h tr-tree.h usage.h utils.h varinfo.h web100-admin.h web100srv.h ndt_odbc.h runningtest.h ndtptestconstants.h \ + heuristics.h strlutils.h test_results_clt.h tests_srv.h jsonutils.h unit_testing.h websocket.h third_party/safe_iop.h + diff --git a/src/connection.h b/src/connection.h deleted file mode 100644 index 531d49f..0000000 --- a/src/connection.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef SRC_CONNECTION_H -#define SRC_CONNECTION_H - -#include - -typedef struct connectionStruct { - int socket; - SSL* ssl; // If ssl != NULL, then it is an SSL connection. -} Connection; - -#endif // SRC_CONNECTION_H diff --git a/src/network.c b/src/network.c index e2544d2..8a8db82 100644 --- a/src/network.c +++ b/src/network.c @@ -8,8 +8,6 @@ #include #include -#include -#include #include #include #include "jsonutils.h" @@ -372,8 +370,8 @@ int CreateConnectSocket(int* sockfd, I2Addr local_addr, I2Addr server_addr, } /** - * Converts message to JSON format and sends it to the control Connection. - * @param ctl control Connection + * Converts message to JSON format and sends it to the control socket. + * @param ctlSocket control socket * @param type type of the message * @param msg message to send * @param len length of the message @@ -407,18 +405,18 @@ int CreateConnectSocket(int* sockfd, I2Addr local_addr, I2Addr server_addr, * -4 - Cannot convert msg to JSON * */ -int send_json_msg_any(Connection* ctl, int type, const char* msg, int len, - int connectionFlags, int jsonConvertType, - const char *keys, const char *keysDelimiters, - const char *values, char *valuesDelimiters) { +int send_json_msg(int ctlSocket, int type, const char* msg, int len, + int connectionFlags, int jsonConvertType, + const char *keys, const char *keysDelimiters, + const char *values, char *valuesDelimiters) { char* tempBuff; int ret = 0; // if JSON is not supported by second side, sends msg as it is if (!(connectionFlags & JSON_SUPPORT)) { if (connectionFlags & WEBSOCKET_SUPPORT) { - return send_websocket_msg(ctl, type, msg, len); + return send_websocket_msg(ctlSocket, type, msg, len); } else { - return send_msg_any(ctl, type, msg, len); + return send_msg(ctlSocket, type, msg, len); } } @@ -432,9 +430,9 @@ int send_json_msg_any(Connection* ctl, int type, const char* msg, int len, tempBuff = json_create_from_key_value_pairs(msg); break; default: if (connectionFlags & WEBSOCKET_SUPPORT) { - return send_websocket_msg(ctl, type, msg, len); + return send_websocket_msg(ctlSocket, type, msg, len); } else { - return send_msg_any(ctl, type, msg, len); + return send_msg(ctlSocket, type, msg, len); } } @@ -442,9 +440,9 @@ int send_json_msg_any(Connection* ctl, int type, const char* msg, int len, return -4; } if (connectionFlags & WEBSOCKET_SUPPORT) { - ret = send_websocket_msg(ctl, type, tempBuff, strlen(tempBuff)); + ret = send_websocket_msg(ctlSocket, type, tempBuff, strlen(tempBuff)); } else { - ret = send_msg_any(ctl, type, tempBuff, strlen(tempBuff)); + ret = send_msg(ctlSocket, type, tempBuff, strlen(tempBuff)); } free(tempBuff); return ret; @@ -454,15 +452,15 @@ int send_json_msg_any(Connection* ctl, int type, const char* msg, int len, * Shortest version of send_json_msg method. Uses default NULL values for * JSON_MULTIPLE_VALUES convert type specific parameters. */ -int send_json_message_any(Connection* ctl, int type, const char* msg, int len, +int send_json_message(int ctlSocket, int type, const char* msg, int len, int connectionFlags, int jsonConvertType) { - return send_json_msg_any(ctl, type, msg, len, connectionFlags, jsonConvertType, - NULL, NULL, NULL, NULL); + return send_json_msg(ctlSocket, type, msg, len, connectionFlags, jsonConvertType, + NULL, NULL, NULL, NULL); } /** - * Sends the protocol message to the control connection. - * @param ctl control Connection + * Sends the protocol message to the control socket. + * @param ctlSocket control socket * @param type type of the message * @param msg message to send * @param len length of the message @@ -472,7 +470,7 @@ int send_json_message_any(Connection* ctl, int type, const char* msg, int len, * -2 - Cannot complete writing full message data into socket * -3 - Cannot write after retries */ -int send_msg_any(Connection* ctl, int type, const void* msg, int len) { +int send_msg(int ctlSocket, int type, const void* msg, int len) { unsigned char buff[3]; int rc, i; @@ -488,7 +486,7 @@ int send_msg_any(Connection* ctl, int type, const void* msg, int len) { // retry sending data 5 times for (i = 0; i < 5; i++) { // Write initial data about length and type to socket - rc = writen_any(ctl, buff, 3); + rc = writen(ctlSocket, buff, 3); if (rc == 3) // write completed break; if (rc == 0) // nothing written yet, @@ -503,7 +501,7 @@ int send_msg_any(Connection* ctl, int type, const void* msg, int len) { // Now write the actual message for (i = 0; i < 5; i++) { - rc = writen_any(ctl, msg, len); + rc = writen(ctlSocket, msg, len); // all the data has been written successfully if (rc == len) break; @@ -518,14 +516,14 @@ int send_msg_any(Connection* ctl, int type, const void* msg, int len) { log_println(8, ">>> send_msg: type=%d, len=%d, msg=%s, pid=%d", type, len, msg, getpid()); - protolog_sendprintln(type, msg, len, getpid(), ctl->socket); + protolog_sendprintln(type, msg, len, getpid(), ctlSocket); return 0; } /** * Receive the protocol message from the control socket. - * @param ctl control Connection + * @param ctlSocket control socket * @param type target place for type of the message * @param msg target place for the message body * @param len target place for the length of the message @@ -535,7 +533,7 @@ int send_msg_any(Connection* ctl, int type, const void* msg, int len) { * -2 : No of bytes received were lesser than expected byte count * -3 : No of bytes received did not match expected byte count */ -int recv_msg_any(Connection* ctl, int* type, void* msg, int* len) { +int recv_msg(int ctlSocket, int* type, void* msg, int* len) { unsigned char buff[3]; int length; char *msgtemp = (char*) msg; @@ -545,7 +543,7 @@ int recv_msg_any(Connection* ctl, int* type, void* msg, int* len) { assert(len); // if 3 bytes are not explicitly read, signal error - if (readn_any(ctl, buff, 3) != 3) { + if (readn(ctlSocket, buff, 3) != 3) { return -1; } @@ -561,22 +559,22 @@ int recv_msg_any(Connection* ctl, int* type, void* msg, int* len) { return -2; } *len = length; - if (readn_any(ctl, msg, length) != length) { + if (readn(ctlSocket, msg, length) != length) { return -3; } log_println(8, "<<< recv_msg: type=%d, len=%d", *type, *len); - protolog_rcvprintln(*type, msgtemp, *len, getpid(), ctl->socket); + protolog_rcvprintln(*type, msgtemp, *len, getpid(), ctlSocket); return 0; } -int recv_any_msg(Connection* conn, int* type, void* msg, int* len, +int recv_any_msg(int ctlSocket, int* type, void* msg, int* len, int connectionFlags) { if (connectionFlags & WEBSOCKET_SUPPORT) { - return recv_websocket_ndt_msg(conn, type, msg, len); + return recv_websocket_ndt_msg(ctlSocket, type, msg, len); } else { - return recv_msg_any(conn, type, msg, len); + return recv_msg(ctlSocket, type, msg, len); } } @@ -585,26 +583,23 @@ int recv_any_msg(Connection* conn, int* type, void* msg, int* len, * @param conn the Connection * @param buf buffer with data to write * @param amount the size of the data - * @return The amount of bytes written to the Connection + * @return The amount of bytes written to the file descriptor */ -int writen_any(Connection* conn, const void* buf, int amount) { + +int writen(int fd, const void* buf, int amount) { int sent, n; const char* ptr = buf; sent = 0; assert(amount >= 0); while (sent < amount) { - if (conn->ssl == NULL) { - n = write(conn->socket, ptr + sent, amount - sent); - } else { - n = SSL_write(conn->ssl, ptr + sent, amount - sent); - } + n = write(fd, ptr + sent, amount - sent); if (n == -1) { if (errno == EINTR) // interrupted, retry writing again continue; if (errno != EAGAIN) { // some genuine socket write error log_println(6, - "writen() Error! write(%d) failed with err='%s(%d) pid=%d'", - conn->socket, strerror(errno), errno, getpid()); + "writen() Error! write(%d) failed with err='%s(%d) pic=%d'", + fd, strerror(errno), errno, getpid()); return -1; } } @@ -641,6 +636,8 @@ size_t readn_raw(int fd, void *buf, size_t amount) { struct timeval sel_tv; fd_set rfd; + assert(amount >= 0); + FD_ZERO(&rfd); // initialize with zeroes FD_SET(fd, &rfd); sel_tv.tv_sec = 600; @@ -668,13 +665,16 @@ size_t readn_raw(int fd, void *buf, size_t amount) { continue; n = read(fd, ptr + received, amount - received); if (n == -1) { // error - if (errno == EINTR) continue; // interrupted, try reading again - if (errno != EAGAIN) return -errno; // genuine socket error, return + if (errno == EINTR) // interrupted , try reading again + continue; + if (errno != EAGAIN) // genuine socket read error, return + return -errno; } if (n != -1) { // if no errors reading, increment data byte count received += n; } - if (n == 0) return 0; + if (n == 0) + return 0; } return received; } diff --git a/src/network.h b/src/network.h index 8def7fe..ced877c 100644 --- a/src/network.h +++ b/src/network.h @@ -10,8 +10,6 @@ #define SRC_NETWORK_H_ #include -#include "connection.h" -#include "testoptions.h" #define NDT_BACKLOG 5 #define BUFFSIZE 8192 @@ -19,21 +17,23 @@ #define OPT_IPV6_ONLY 1 #define OPT_IPV4_ONLY 2 +#define JSON_SUPPORT 1 +#define WEBSOCKET_SUPPORT 2 + I2Addr CreateListenSocket(I2Addr addr, char* serv, int options, int buf_size); int CreateConnectSocket(int* sockfd, I2Addr local_addr, I2Addr server_addr, int option, int buf_sizes); -int send_json_msg_any(Connection* conn, int type, const char* msg, int len, - int connectionFlags, int jsonConvertType, - const char *keys, const char *keysDelimiters, - const char *values, char *valuesDelimiters); -int send_json_message_any(Connection* ctl, int type, const char* msg, int len, - int connectionFlags, int jsonConvertType); -int send_msg_any(Connection* conn, int type, const void* msg, int len); -int recv_msg_any(Connection* conn, int* type, void* msg, int* len); -int recv_any_msg(Connection* conn, int* type, void* msg, int* len, - int connectionFlags); -int writen_any(Connection* conn, const void* buf, int amount); -size_t readn_any(Connection* conn, void* buf, size_t amount); +int send_json_msg(int ctlSocket, int type, const char* msg, int len, + int connectionFlags, int jsonConvertType, + const char *keys, const char *keysDelimiters, + const char *values, char *valuesDelimiters); +int send_json_message(int ctlSocket, int type, const char* msg, int len, + int connectionFlags, int jsonConvertType); +int send_msg(int ctlSocket, int type, const void* msg, int len); +int recv_msg(int ctlSocket, int* type, void* msg, int* len); +int recv_any_msg(int ctlSocket, int* type, void* msg, int* len, int connectionFlags); +int writen(int fd, const void* buf, int amount); +size_t readn(int fd, void* buf, size_t amount); /* web100-util.c routine used in network. */ int KillHung(void); diff --git a/src/network_clt.c b/src/network_clt.c deleted file mode 100644 index 1f898d9..0000000 --- a/src/network_clt.c +++ /dev/null @@ -1,117 +0,0 @@ -#include "network_clt.h" -#include "network.h" - -/** - * Converts message to JSON format and sends it to the control socket. - * @param ctlSocket control socket - * @param type type of the message - * @param msg message to send - * @param len length of the message - * @param connectionFlags indicates if JSON format is supported by the other side (connectionFlags & JSON_SUPPORT) - * and if websockets are supported by the other side (connectionFlags & WEBSOCKET_SUPPORT) - * It is expected, but not required, that WEBSOCKET_SUPPORT will always include JSON_SUPPORT. - * @param jsonConvertType defines how message converting should be handled: - * JSON_SINGLE_VALUE: single key/value pair is being created (using default key) - * with msg as value - * JSON_MULTIPLE_VALUES: multiple key/values pairs are being created using - * keys, keys_delimiters, values and values_delimiters - * params - * JSON_KEY_VALUE_PAIRS: given message contains one or many key/value pairs - * with following syntax: key1: value1 - * key2: value2 etc - * @param keys buffer containing keys' values (used only when jsonConvertType is set to - * JSON_MULTIPLE_VALUES) - * @param keysDelimiters delimiters for keys parameter (used only when jsonConvertType is set to - * JSON_MULTIPLE_VALUES) - * @param values buffer containing map values, key-value matching is being done by order in which - * they appear in keys and values params (used only when jsonConvertType is set to - * JSON_MULTIPLE_VALUES) - * @param valuesDelimiters delimiters for values parameter (used only when jsonConvertType is - * set to JSON_MULTIPLE_VALUES) - * - * @return 0 on success, error code otherwise - * Error codes: - * -1 - Cannot write to socket at all - * -2 - Cannot complete writing full message data into socket - * -3 - Cannot write after retries - * -4 - Cannot convert msg to JSON - */ -int send_json_msg(int ctlSocket, int type, const char* msg, int len, - int connectionFlags, int jsonConvertType, - const char *keys, const char *keysDelimiters, - const char *values, char *valuesDelimiters) { - Connection ctl = {ctlSocket, NULL}; - return send_json_msg_any(&ctl, type, msg, len, connectionFlags, - jsonConvertType, keys, keysDelimiters, values, - valuesDelimiters); -} - -/** - * Shortest version of send_json_msg method. Uses default NULL values for - * JSON_MULTIPLE_VALUES convert type specific parameters. - */ -int send_json_message(int ctlSocket, int type, const char* msg, int len, - int connectionFlags, int jsonConvertType) { - Connection ctl = {ctlSocket, NULL}; - return send_json_message_any(&ctl, type, msg, len, connectionFlags, jsonConvertType); -} - - -/** - * Sends the protocol message to the control socket. - * @param ctlSocket control socket - * @param type type of the message - * @param msg message to send - * @param len length of the message - * @return 0 on success, error code otherwise - * Error codes: - * -1 - Cannot write to socket at all - * -2 - Cannot complete writing full message data into socket - * -3 - Cannot write after retries - */ -int send_msg(int ctlSocket, int type, const void* msg, int len) { - Connection conn = {ctlSocket, NULL}; - return send_msg_any(&conn, type, msg, len); -} - -/** - * Receive the protocol message from the control socket. - * @param ctlSocket control socket - * @param type target place for type of the message - * @param msg target place for the message body - * @param len target place for the length of the message - * @returns 0 on success, error code otherwise. - * Error codes: - * -1 : Error reading from socket - * -2 : No of bytes received were lesser than expected byte count - * -3 : No of bytes received did not match expected byte count - */ -int recv_msg(int ctlSocket, int* type, void* msg, int* len) { - Connection ctl = {ctlSocket, NULL}; - return recv_msg_any(&ctl, type, msg, len); -} - -/** - * Write the given amount of data to the file descriptor. - * @param fd the file descriptor - * @param buf buffer with data to write - * @param amount the size of the data - * @return The amount of bytes written to the file descriptor - */ -int writen(int fd, const void* buf, int amount) { - Connection connection = {fd, NULL}; - return writen_any(&connection, buf, amount); -} - -/** - * Read the given amount of data from the file descriptor. - * @param fd the file descriptor - * @param buf buffer for data - * @param amount size of the data to read - * @return The amount of bytes read from the file descriptor - */ -size_t readn(int fd, void* buf, size_t amount) { - Connection conn = {fd, NULL}; - return readn_any(&conn, buf, amount); -} - diff --git a/src/network_clt.h b/src/network_clt.h deleted file mode 100644 index 5c95ea7..0000000 --- a/src/network_clt.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef SRC_NETWORK_CLT_H_ -#define SRC_NETWORK_CLT_H_ - -#include "network.h" - -int send_json_msg(int ctlSocket, int type, const char* msg, int len, - int connectionFlags, int jsonConvertType, - const char *keys, const char *keysDelimiters, - const char *values, char *valuesDelimiters); -int send_json_message(int ctlSocket, int type, const char* msg, int len, - int connectionFlags, int jsonConvertType); -int send_msg(int ctlSocket, int type, const void* msg, int len); -int recv_msg(int ctlSocket, int* type, void* msg, int* len); -int writen(int fd, const void* buf, int amount); -size_t readn(int fd, void* buf, size_t amount); - -#endif // SRC_NETWORK_CLT_H_