Skip to content

Commit

Permalink
Fix some warnings and windows build
Browse files Browse the repository at this point in the history
Todo fix tests on windows
  • Loading branch information
matt-attack committed Jun 23, 2024
1 parent db52b7a commit 67fb772
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion include/pubsub/TCPTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ int ps_tcp_transport_spin(struct ps_transport_t* transport, struct ps_node_t* no
{
printf("Failed to Set Socket as Non-Blocking!\n");
closesocket(socket);
return;
return 0;
}
#endif
#ifdef ARDUINO
Expand Down
6 changes: 5 additions & 1 deletion include/pubsub_cpp/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
#include <memory>


//#include <WS2tcpip.h>
// todo sometime fix this needing to be here for windows
// might be a tcp issue
#ifdef _WIN32
#include <WS2tcpip.h>
#endif
#include <pubsub/Events.h>

namespace pubsub
Expand Down
10 changes: 5 additions & 5 deletions include/pubsub_cpp/Serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ ps_msg_t serialize_value(const Value& value, const ps_message_definition_t& defi
if (value.type != Array)
{
// just write the same value n times
int size = ps_field_sizes[field.type];
size_t size = ps_field_sizes[field.type];
float data = value.type == None ? 0.0 : value.flt;
for (unsigned int i = 0; i < field.length; i++)
{
Expand All @@ -191,9 +191,9 @@ ps_msg_t serialize_value(const Value& value, const ps_message_definition_t& defi
{
// fill it in using the array
// just write the same value n times
int size = ps_field_sizes[field.type];
size_t size = ps_field_sizes[field.type];
float data = value.type == None ? 0.0 : value.flt;
int len = field.length == 0 ? value.arr.size() : field.length;
size_t len = field.length == 0 ? value.arr.size() : field.length;
for (unsigned int i = 0; i < len; i++)
{
float data = i < value.arr.size() ? value.arr[i].flt : 0.0;
Expand Down Expand Up @@ -238,8 +238,8 @@ ps_msg_t serialize_value(const Value& value, const ps_message_definition_t& defi
pos += 4;
}
//printf("len: %i at %i\n", len, pos-start);
int size = ps_field_sizes[field.type];
for (unsigned int j = 0; j < len; j++)
size_t size = ps_field_sizes[field.type];
for (size_t j = 0; j < len; j++)
{
double data = j < value.arr.size() ? value.arr[j].flt : 0.0;
memcpy(pos, &data, 8);
Expand Down
6 changes: 3 additions & 3 deletions src/Events.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void ps_event_set_add_socket_write(struct ps_event_set_t* set, int socket)
{
#ifdef WIN32
// find the handle and change the select
for (int i = 0; i < set->num_handles; i++)
for (unsigned int i = 0; i < set->num_handles; i++)
{
if (set->sockets[i] == socket)
{
Expand Down Expand Up @@ -117,7 +117,7 @@ void ps_event_set_remove_socket_write(struct ps_event_set_t* set, int socket)
{
#ifdef WIN32
// find the handle and change the select
for (int i = 0; i < set->num_handles; i++)
for (unsigned int i = 0; i < set->num_handles; i++)
{
if (set->sockets[i] == socket)
{
Expand All @@ -139,7 +139,7 @@ void ps_event_set_remove_socket(struct ps_event_set_t* set, int socket)
#ifdef WIN32
// find the socket to remove then remove it
bool found = false;
int index = 0;
unsigned int index = 0;
for (; index < set->num_handles; index++)
{
if (set->sockets[index] == socket)
Expand Down
2 changes: 1 addition & 1 deletion src/Subscriber.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void ps_sub_destroy(struct ps_sub_t* sub)
ps_udp_unsubscribe(sub);

// unsubcribe from all other transports
for (int i = 0; i < sub->node->num_transports; i++)
for (unsigned int i = 0; i < sub->node->num_transports; i++)
{
sub->node->transports[i].unsubscribe(&sub->node->transports[i], sub);
}
Expand Down
7 changes: 7 additions & 0 deletions tests/test_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ int ps_okay();
#include <sstream>
#include <fstream>

#ifdef _WIN32
#include <io.h>
#endif
#include <pubsub_cpp/Node.h>
#include <pubsub_cpp/Spinners.h>

Expand All @@ -41,7 +44,9 @@ std::string execute_command(const std::vector<std::string>& args)
int bak, nnew;
fflush(stdout);
bak = dup(1);
#ifndef _WIN32
nnew = open(tmp_file, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);
#endif
dup2(nnew, 1);
close(nnew);

Expand All @@ -55,7 +60,9 @@ std::string execute_command(const std::vector<std::string>& args)

// Restore stdout
fflush(stdout);
#ifndef _WIN32
dup2(bak, STDOUT_FILENO);
#endif
close(nnew);

// Read in captured std out output
Expand Down
3 changes: 3 additions & 0 deletions tools/pubsub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#include <sstream>
#include <fstream>

#undef max
#undef min


using namespace std;

Expand Down

0 comments on commit 67fb772

Please sign in to comment.