Commit c9155f5d authored by Greg Williams's avatar Greg Williams
Browse files

Merge branch 'feature/noop' into develop

parents 973310b4 d6377ba9
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -165,8 +165,13 @@ namespace :java_sim do
    # Ensure stray simulators are not still running
    `ps -ef | grep kinetic-simulator`.each_line do |l|
      next if l =~ /grep kinetic-simulator/
      pid = l.match /^\w*\d+\w+(\d+)/
      sh "kill -9 pid[1]" if pid
      pid = l.match /^\s*\d+\s+(\d+)/
      if pid
        sh "kill -9 #{pid[1]}"
        report "Killed Java simulator with PID: #{pid[1]}"
      else
        report "Did not find any running Java Kinetic simulators"
      end
    end
  end

@@ -229,7 +234,7 @@ end

desc "Run client test utility"
task :run do
  execute_command "./build/release/kinetic-c-client", "Running client test utility"
  execute_command "./build/artifacts/release/kinetic-c", "Running client test utility"
end

desc "Prepend license to source files"
+4 −4
Original line number Diff line number Diff line
@@ -87,8 +87,8 @@
      - -D"$": COLLECTION_DEFINES_TEST_AND_VENDOR
      - -D"$": DEFINES_TEST_PREPROCESS
      - -DGNU_COMPILER
      - -std=c99
      - -Wall
      # - -std=c99
      # - -Wall
      - ${1}
  :test_linker:
    :executable: gcc
@@ -112,8 +112,8 @@
      - -I"$": 'COLLECTION_PATHS_RELEASE_TOOLCHAIN_INCLUDE'
      - -D"$": 'COLLECTION_DEFINES_RELEASE_AND_VENDOR'
      - -DGNU_COMPILER
      - -std=c99
      - -Wall
      # - -std=c99
      # - -Wall
      - "-c \"${1}\""
      - "-o \"${2}\""
  :release_linker:
+1 −132
Original line number Diff line number Diff line
@@ -39,137 +39,7 @@
    #define _BSD_SOURCE
#endif // _BSD_SOURCE
#include <unistd.h>

int KineticSocket_GetSocketError(int fd)
{
    int err = 1;
    socklen_t len = sizeof err;
    
    if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (char *)&err, &len) == -1)
    {
        LOG("Failed to get socket options!");
    }

    if (err)
    {
        errno = err; // set errno to the socket SO_ERROR
    }

    return err;
}

bool KineticSocket_HaveInput(int fd, double timeout)
{
    int status;
    fd_set fds;
    struct timeval tv;
    FD_ZERO(&fds);
    FD_SET(fd, &fds);
    tv.tv_sec  = (long)timeout; // cast needed for C++
    tv.tv_usec = (long)((timeout - tv.tv_sec) * 1000000); // 'suseconds_t'

    while (1)
    {
        if (!(status = select(fd + 1, &fds, 0, 0, &tv)))
        {
            return false;
        }
        else if (status > 0 && FD_ISSET(fd, &fds))
        {
            return true;
        }
        else if (status > 0)
        {
            LOG("I am confused!!!");
        }
        else if (errno != EINTR)
        {
            LOG("Failed select upon flush!"); // tbd EBADF: man page "an error has occurred"
        }
    }
}

bool KineticSocket_FlushSocketBeforeClose(int fd/*, double timeout*/)
{
    // const double start = getWallTimeEpoch();
    char discard[99];
    int i, iterations = 5;

    assert(SHUT_WR == 1);

    if (shutdown(fd, 1) != -1)
    {
        for (i = 0; i < iterations; i++)
        {
            while (KineticSocket_HaveInput(fd, 0.01)) // can block for 0.01 secs
            {
                if (!read(fd, discard, sizeof discard))
                {
                    return true; // success!
                }
            }
        }
    }

   return false;
}

bool KineticSocket_CloseSocket(int fd)
{
    if (fd >= 0)
    {
        char msg[64];
        int err;

        LOG("KineticSocket_CloseSocket");

        if (!KineticSocket_FlushSocketBeforeClose(fd))
        {
            LOG("Failed to gracefully close socket!");
        }
        else
        {
            LOG("Socket flushed successfully");
        }
        
        err = KineticSocket_GetSocketError(fd); // first clear any errors, which can cause close to fail
        if (err)
        {
            sprintf(msg, "Socket error had occurred: err=%d", err);
            LOG(msg);
        }
        else
        {
            LOG("Socket errors cleared successfully!");
        }
        
        if (shutdown(fd, SHUT_RDWR) < 0) // secondly, terminate the 'reliable' delivery
        {
            if (errno != ENOTCONN && errno != EINVAL) // SGI causes EINVAL
            {
                sprintf(msg, "Socket error occurred! errno=%d", errno);
                return false;
            }

            if (close(fd) < 0) // finally call close()
            {
                LOG("Failed closing socket!");
                return false;
            }
            else
            {
                LOG("Succeeded closing socket");
            }
        }
        else
        {
            LOG("Call to shutdown socket failed!");
            return false;
        }
    }

    return true;
}
#include <sys/types.h>

int KineticSocket_Connect(char* host, int port, bool blocking)
{
@@ -265,7 +135,6 @@ void KineticSocket_Close(int socketDescriptor)
    {
        sprintf(message, "Closing socket with fd=%d", socketDescriptor);
        LOG(message);
        // if (KineticSocket_CloseSocket(socketDescriptor))
        if (close(socketDescriptor))
        {
            LOG("Socket closed successfully");
+1 −0
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@
    #define _BSD_SOURCE
#endif // _BSD_SOURCE
#include <unistd.h>
#include <sys/types.h>
#ifndef HOST_NAME_MAX
    #define HOST_NAME_MAX 256
#endif // HOST_NAME_MAX
+2 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
*/

#include "unity_helper.h"
#include "kinetic_types.h"
#include "kinetic_socket.h"
#include "kinetic_logger.h"
#include "kinetic_proto.h"
@@ -29,6 +30,7 @@
    #define _BSD_SOURCE
#endif // _BSD_SOURCE
#include <unistd.h>
#include <sys/types.h>
#include "socket99.h"

#include <errno.h>