Skip to content

Commit

Permalink
Adapt to new socket interface (soc_receive, soc_get_local_lan_name)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pascal MALAISE committed Aug 26, 2013
1 parent a3705bc commit 3517d2d
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 100 deletions.
2 changes: 1 addition & 1 deletion delta_time/delta_time.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ int main (const int argc, const char * argv[]) {
error (buff);
} else {
/* Now this is the socket, read message */
res = soc_receive (soc, (soc_message) &msg, sizeof(msg), TRUE, FALSE);
res = soc_receive (soc, (soc_message) &msg, sizeof(msg), TRUE);
if (res < 0) {
perror ("reading from socket");
error ("Reading message failed");
Expand Down
2 changes: 1 addition & 1 deletion forker/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ int main(int argc, char *argv[]) {

} else if (strcmp(buff, "r") == 0) {
/* Read report */
n = soc_receive(soc, &report, sizeof(report), FALSE, FALSE);
n = soc_receive(soc, &report, sizeof(report), FALSE);
if (n == sizeof(report)) {
switch (report.kind) {
case start_report :
Expand Down
2 changes: 1 addition & 1 deletion forker/forker.c
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ int main (int argc, char *argv[]) {

/* Read request */
request_len = soc_receive(client_soc, &request_message,
sizeof(request_message), (proto != Tcp), FALSE);
sizeof(request_message), (proto != Tcp));

/* Handle Tcp disconnection */
if ((proto == Tcp) && ( (request_len == SOC_CONN_LOST)
Expand Down
2 changes: 1 addition & 1 deletion gorgy/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void init_udp (char *port_name_no) {
int cr;
char lan_name[80];

if (soc_get_lan_name(lan_name, sizeof(lan_name)) != SOC_OK) {
if (soc_get_local_lan_name(lan_name, sizeof(lan_name)) != SOC_OK) {
perror("getting lan name");
exit (2);
}
Expand Down
5 changes: 2 additions & 3 deletions locale/locale.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ int main (int argc, char *argv[]) {

(void) setlocale(LC_ALL, "");

if (argc < 2) help(argv);
if ( argc < 2 ) help(argv);
else draw (argv, argc, ONE);
exit (0);
exit(0);
}

static void help (char *str[]) {
Expand Down Expand Up @@ -57,6 +57,5 @@ static void draw (char *str[], int count, char param) {

printf ("+-----------+-----+-----+-----+\n");


}

4 changes: 2 additions & 2 deletions synchro/synchro_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ int main (int argc, char *argv[]) {
accuracy_timeout.tv_usec = (accuracy_ms % 1000) * 1000;


if (soc_get_lan_name(lan_name, sizeof(lan_name)) != SOC_OK) {
if (soc_get_local_lan_name(lan_name, sizeof(lan_name)) != SOC_OK) {
perror ("getting lan name");
exit (1);
}
Expand Down Expand Up @@ -134,7 +134,7 @@ int main (int argc, char *argv[]) {
}

length = sizeof (synchro_msg);
cr = soc_receive (soc, (soc_message) &synchro_msg, length, FALSE, FALSE);
cr = soc_receive (soc, (soc_message) &synchro_msg, length, FALSE);
get_time (&reply_time);

if ( cr == sizeof (synchro_msg) ) {
Expand Down
2 changes: 1 addition & 1 deletion synchro/synchro_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ int main (int argc, char *argv[]) {
/* Wait for request and reply with current time */
for (;;) {
length = sizeof (synchro_msg);
cr = soc_receive (soc, (soc_message) &synchro_msg, length, FALSE, FALSE);
cr = soc_receive (soc, (soc_message) &synchro_msg, length, FALSE);
if ( (cr == sizeof (synchro_msg))
&& (synchro_msg.magic_number == magic_request_value) ) {

Expand Down
2 changes: 1 addition & 1 deletion udp_send/udp_send.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ int main (int argc, char *argv[]) {
res = soc_set_blocking (soc, FALSE);
sleep (1);
for (;;) {
res = soc_receive (soc, message, (soc_length)sizeof(message), TRUE, FALSE);
res = soc_receive (soc, message, (soc_length)sizeof(message), TRUE);
if (res > 0) {
message[res] = '\0';
printf ("-->%s<\n", message);
Expand Down
178 changes: 89 additions & 89 deletions udpspy/udpspy.c
Original file line number Diff line number Diff line change
@@ -1,89 +1,89 @@
#include "timeval.h"
#include "socket.h"
#include "wait_evt.h"
#include "util.h"

/* Message read */
static char message[128*1024];

int main (const int argc, const char *argv[]) {
/* Result of operation */
int res;
char buffer[255];

/* The socket and its fd */
soc_token socket = init_soc;
int fd;

/* Event result */
boolean read;
timeout_t timeout;
int evtfd;

/* parse arguments */
parse_args (argc, argv);

/* Create socket and get fd */
if ( (res = soc_open (&socket, udp_socket)) != SOC_OK) {
trace ("soc_open error", soc_error (res));
error ("cannot open socket", "");
}
if ( (res = soc_get_id (socket, &fd)) != SOC_OK) {
trace ("soc_get_id error", soc_error (res));
error ("cannot get socket fd", "");
}
/* Bind socket to lan:port */
bind_socket (socket);

/* Attach fd for reading */
if ( (res = evt_add_fd (fd, TRUE)) != WAIT_OK) {
trace ("evt_add_fd error", "");
error ("cannot add fd", "");
}

/* Main loop */
timeout.tv_sec = -1;
timeout.tv_usec = -1;
for (;;) {
/* Infinite wait for events */
if ( (res = evt_wait (&evtfd, & read, &timeout)) != WAIT_OK) {
trace ("evt_wait error", "");
error ("cannot wait for event", "");
}
/* Analyse event */
if (evtfd == SIG_EVENT) {
if (get_signal() == SIG_TERMINATE) {
/* Sigterm/sigint */
break;
} /* else unexpected signal => drop */
} else if (evtfd == fd) {
/* Got a packet: read it */
res = soc_receive (socket, message, sizeof(message), TRUE, FALSE);
if (res < 0) {
sprintf (buffer, "%d", res);
trace ("soc_receive error", soc_error (res));
error ("cannot read message", soc_error(res));
} else {
if (res > (int)sizeof(message)) {
sprintf (buffer, "%d", res);
trace ("soc_receive truncated message length", "buffer");
res = (int)sizeof(message);
}
/* Put message info */
display (socket, message, res);
}
} else if (evtfd >= 0) {
/* Unexpected event on an unexpected fd */
sprintf (buffer, "%d", evtfd);
trace ("evt_wait got unexpected even on fd", "buffer");
error ("even on unexpected fd", "");
}

} /* Main loop */

/* Done */
(void) evt_del_fd (fd, TRUE);
(void) soc_close (&socket);
the_end ();
}

#include "timeval.h"
#include "socket.h"
#include "wait_evt.h"
#include "util.h"

/* Message read */
static char message[128*1024];

int main (const int argc, const char *argv[]) {
/* Result of operation */
int res;
char buffer[255];

/* The socket and its fd */
soc_token socket = init_soc;
int fd;

/* Event result */
boolean read;
timeout_t timeout;
int evtfd;

/* parse arguments */
parse_args (argc, argv);

/* Create socket and get fd */
if ( (res = soc_open (&socket, udp_socket)) != SOC_OK) {
trace ("soc_open error", soc_error (res));
error ("cannot open socket", "");
}
if ( (res = soc_get_id (socket, &fd)) != SOC_OK) {
trace ("soc_get_id error", soc_error (res));
error ("cannot get socket fd", "");
}
/* Bind socket to lan:port */
bind_socket (socket);

/* Attach fd for reading */
if ( (res = evt_add_fd (fd, TRUE)) != WAIT_OK) {
trace ("evt_add_fd error", "");
error ("cannot add fd", "");
}

/* Main loop */
timeout.tv_sec = -1;
timeout.tv_usec = -1;
for (;;) {
/* Infinite wait for events */
if ( (res = evt_wait (&evtfd, & read, &timeout)) != WAIT_OK) {
trace ("evt_wait error", "");
error ("cannot wait for event", "");
}
/* Analyse event */
if (evtfd == SIG_EVENT) {
if (get_signal() == SIG_TERMINATE) {
/* Sigterm/sigint */
break;
} /* else unexpected signal => drop */
} else if (evtfd == fd) {
/* Got a packet: read it */
res = soc_receive (socket, message, sizeof(message), TRUE);
if (res < 0) {
sprintf (buffer, "%d", res);
trace ("soc_receive error", soc_error (res));
error ("cannot read message", soc_error(res));
} else {
if (res > (int)sizeof(message)) {
sprintf (buffer, "%d", res);
trace ("soc_receive truncated message length", "buffer");
res = (int)sizeof(message);
}
/* Put message info */
display (socket, message, res);
}
} else if (evtfd >= 0) {
/* Unexpected event on an unexpected fd */
sprintf (buffer, "%d", evtfd);
trace ("evt_wait got unexpected even on fd", "buffer");
error ("even on unexpected fd", "");
}

} /* Main loop */

/* Done */
(void) evt_del_fd (fd, TRUE);
(void) soc_close (&socket);
the_end ();
}

0 comments on commit 3517d2d

Please sign in to comment.