Skip to content

Commit

Permalink
src: Code enhancement
Browse files Browse the repository at this point in the history
Opportunistic code enhancing done to ease code viewing
and understanding. No functional changed.

Signed-off-by: Gan, Yi Fang <[email protected]>
  • Loading branch information
ganyifang authored and ws-intel committed Oct 9, 2023
1 parent cfca981 commit c69b3b3
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/opcua-tsn/multicallback_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ static UA_Server *setupOpcuaServer(struct ServerData *sdata)

void copy_file(char *src_file, char *dst_file, bool clear_src)
{
char ch;
int ch;
FILE *src, *dst;

/* Open source file for reading */
Expand Down
4 changes: 2 additions & 2 deletions src/opcua-tsn/opcua_datasource.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ subStoreDataReceived(UA_Server *server, const UA_NodeId *sessionId,
}

if (g_sData->msqid >= 0) {
ret = msgsnd(g_sData->msqid, (void *)&msgqB, sizeof(struct msgq_buf), IPC_NOWAIT);
ret = msgsnd(g_sData->msqid, (void *)&msgqB, sizeof(struct msgq_buf) - sizeof(msgqB.msg_type), IPC_NOWAIT);
if (ret < 0) {
if (errno == EAGAIN) {
debug("msgsnd: queue is full\n");
Expand Down Expand Up @@ -222,7 +222,7 @@ pubReturnGetDataToTransmit(UA_Server *server, const UA_NodeId *sessionId,

/* Give a window of 150us */
for (int i = 0; i < 15; i++) {
ret = msgrcv(g_sData->msqid, (void *)&msgqC, sizeof(struct msgq_buf),
ret = msgrcv(g_sData->msqid, (void *)&msgqC, sizeof(struct msgq_buf) - sizeof(msgqC.msg_type),
MSGQ_TYPE, IPC_NOWAIT);
if (ret < 0) {
if (errno == EAGAIN) {
Expand Down
10 changes: 5 additions & 5 deletions src/tsq.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ void listener(struct opt *user_opt) {
error("[TSQ-L] Error opening listening socket\n");

// connection settings
memset(&serv, '0', sizeof(serv));
memset(&serv, 0, sizeof(serv));
serv.sin_family = AF_INET;
serv.sin_addr.s_addr = inet_addr(server_ip);
if (user_opt->port != 0)
Expand Down Expand Up @@ -414,7 +414,7 @@ void listener(struct opt *user_opt) {
for (int i = 0; i < CLIENT_COUNT; i++) {

bzero(recv_buff, BUFFER_SIZE);
memset(&temp_data, '0', sizeof(temp_data));
memset(&temp_data, 0, sizeof(temp_data));
connfd = cli_conns[i];

if (FD_ISSET(connfd, &readfds)) {
Expand Down Expand Up @@ -487,14 +487,14 @@ void listener(struct opt *user_opt) {

case 0:
skip_slot = false;
memset(&keep_data, '0', sizeof(payload));
memset(&keep_data, 0, sizeof(payload));
fprintf(glob_fp, "%d %lld %ld\n", rounds, secs_error, nsecs_error);
rounds++;
break;

default:
skip_slot = false;
memset(&keep_data, '0', sizeof(payload));
memset(&keep_data, 0, sizeof(payload));
printf("[TSQ-L] Waiting for samples alignment...\n");
break;
}
Expand Down Expand Up @@ -540,7 +540,7 @@ void talker(struct opt *user_opt){
printf("[TSQ-T] Assigned uid %d\n", uid);

/* Set up the socket for transmission */
memset(&serv, '0', sizeof(serv));
memset(&serv, 0, sizeof(serv));
serv.sin_family = AF_INET;
serv.sin_addr.s_addr = inet_addr(server_ip);
serv.sin_port = htons(port);
Expand Down
6 changes: 5 additions & 1 deletion src/txrx-afpkt.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ static uint64_t extract_ts_from_cmsg(int sock, int recvmsg_flags)
struct msghdr msg;
struct iovec entry;
struct sockaddr_in from_addr;
int ret = 0;
struct {
struct cmsghdr cm;
char control[512];
Expand All @@ -117,7 +118,9 @@ static uint64_t extract_ts_from_cmsg(int sock, int recvmsg_flags)
msg.msg_control = &control;
msg.msg_controllen = sizeof(control);

recvmsg(sock, &msg, recvmsg_flags|MSG_DONTWAIT);
ret = recvmsg(sock, &msg, recvmsg_flags|MSG_DONTWAIT);
if (ret <= 0)
return 0;

return get_timestamp(&msg);
}
Expand Down Expand Up @@ -529,6 +532,7 @@ int afpkt_recv_pkt(int sock, struct user_opt *opt)
host_address.sin_port = htons(0);
host_address.sin_addr.s_addr = INADDR_ANY;

memset(&msg, 0, sizeof(msg));
iov.iov_base = buffer;
iov.iov_len = 128; //TODO: use correct length based on VLAN header
msg.msg_iov = &iov;
Expand Down
6 changes: 3 additions & 3 deletions src/txrx-afxdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ static struct pkt_buffer *create_umem(void *ubuf, struct xsk_opt *x_opt)
struct pkt_buffer *temp_buff;
uint32_t idx = 0;
int ret;
int i;
__u64 i;

struct xsk_umem_config uconfig = {
.fill_size = x_opt->frames_per_ring,
Expand All @@ -120,7 +120,7 @@ static struct pkt_buffer *create_umem(void *ubuf, struct xsk_opt *x_opt)
.frame_headroom = XSK_UMEM__DEFAULT_FRAME_HEADROOM,
};

single_umem_ring_size = x_opt->frames_per_ring * x_opt->frame_size;
single_umem_ring_size = (uint64_t) (x_opt->frames_per_ring * x_opt->frame_size);

ret = posix_memalign(&ubuf, getpagesize(), /* PAGE_SIZE aligned */
single_umem_ring_size);
Expand Down Expand Up @@ -191,7 +191,7 @@ static struct xsk_info *create_xsk_info(struct user_opt *opt, struct pkt_buffer
static void prefill_tx_umem_rings(void *buff_addr, tsn_packet *example_pkt,
int count, int frame_size)
{
int i;
__u64 i;

for (i = 0; i < count; i++) {
memcpy(xsk_umem__get_data(buff_addr, i * frame_size),
Expand Down
2 changes: 1 addition & 1 deletion src/txrx.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ static struct argp argp = { options, parser, usage, summary };

static void copy_file(char *src_file, char *dst_file, bool clear_src)
{
char ch;
int ch;
FILE *src, *dst;

if (src_file == NULL || dst_file == NULL) {
Expand Down

0 comments on commit c69b3b3

Please sign in to comment.