mirror of
https://github.com/nasa/trick.git
synced 2025-05-21 01:37:45 +00:00
I changed trick comm so that there is only one version built, not a slightly different version if you are in or out of a sim. While I was in the trick comm code, I removed all of the unnecessary system header file inclusions out of tc.h. I modified each of the source files to include the system files it requires. Some sim_services files were including tc.h and also had to be edited to add headers. I removed the stand-alone makefiles out of all of the trick_utils directories. Finally I modified the master makefile to exclude the trick_util directories comm, math, and units from being archived into libtrick.a. Each of those directories will create their own library and will be included when linking a Trick sim. refs #71
87 lines
3.0 KiB
C
87 lines
3.0 KiB
C
|
|
#ifndef __WIN32__
|
|
# include <sys/ioctl.h>
|
|
# define IOCTL_SOCKET ioctl
|
|
#else
|
|
# define IOCTL_SOCKET ioctlsocket
|
|
#endif
|
|
|
|
#include "trick/tc.h"
|
|
#include "trick/tc_proto.h"
|
|
|
|
/*
|
|
*Set a device to BLOCKIO or NOBLOCKIO - may be used as a toggle
|
|
*/
|
|
int tc_blockio(TCDevice * device, TCCommBlocking blockflag)
|
|
{
|
|
char client_str[TC_TAG_LENGTH + 256];
|
|
int on = 1;
|
|
int off = 0;
|
|
|
|
if (device == NULL) {
|
|
return TC_EWOULDBLOCK;
|
|
}
|
|
|
|
/* Status message */
|
|
sprintf(client_str, "(ID = %d tag = %s)", device->client_id, device->client_tag);
|
|
trick_error_report(device->error_handler, TRICK_ERROR_TRIVIAL, __FILE__,
|
|
__LINE__, "%s blockflag = %d\n", client_str, blockflag);
|
|
|
|
|
|
switch (blockflag) {
|
|
|
|
case TC_COMM_BLOCKIO:
|
|
/* Set socket to blocking */
|
|
if (IOCTL_SOCKET(device->socket, (unsigned long) FIONBIO, &off) < 0) {
|
|
trick_error_report(device->error_handler,
|
|
TRICK_ERROR_ALERT, __FILE__, __LINE__, "could not set socket to blocking\n");
|
|
return (TC_EWOULDBLOCK);
|
|
}
|
|
device->blockio_type = blockflag;
|
|
break;
|
|
|
|
case TC_COMM_NOBLOCKIO:
|
|
/* Set socket to non-blocking */
|
|
if (IOCTL_SOCKET(device->socket, (unsigned long) FIONBIO, &on) < 0) {
|
|
trick_error_report(device->error_handler,
|
|
TRICK_ERROR_ALERT, __FILE__, __LINE__, "could not set socket to non-blocking\n");
|
|
return (TC_EWOULDBLOCK);
|
|
}
|
|
device->blockio_type = blockflag;
|
|
break;
|
|
|
|
case TC_COMM_TIMED_BLOCKIO:
|
|
/* Set socket to non-blocking */
|
|
if (IOCTL_SOCKET(device->socket, (unsigned long) FIONBIO, &on) < 0) {
|
|
trick_error_report(device->error_handler,
|
|
TRICK_ERROR_ALERT, __FILE__,
|
|
__LINE__, "could not set socket to software-blocking\n");
|
|
return (TC_EWOULDBLOCK);
|
|
}
|
|
device->blockio_type = blockflag;
|
|
break;
|
|
|
|
case TC_COMM_ALL_OR_NOTHING:
|
|
/* Set socket to non-blocking */
|
|
if (IOCTL_SOCKET(device->socket, (unsigned long) FIONBIO, &on) < 0) {
|
|
trick_error_report(device->error_handler,
|
|
TRICK_ERROR_ALERT, __FILE__, __LINE__, "could not set socket to all_or nothing\n");
|
|
return (TC_EWOULDBLOCK);
|
|
}
|
|
device->blockio_type = blockflag;
|
|
break;
|
|
|
|
default:
|
|
trick_error_report(device->error_handler,
|
|
TRICK_ERROR_ALERT, __FILE__, __LINE__,
|
|
"Invalid second argument."
|
|
"Second argument should be one of the following:\n"
|
|
" TC_COMM_BLOCKIO,\n"
|
|
" TC_COMM_NOBLOCKIO,\n" " TC_COMM_TIMED_BLOCKIO,\n" " TC_COMM_ALL_OR_NOTHING\n\n");
|
|
return (TC_EWOULDBLOCK);
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|