This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
stellar-stellar/src/packet_io/packet_io.cpp

120 lines
2.8 KiB
C++
Raw Normal View History

#include <stdlib.h>
#include <string.h>
2024-04-10 17:50:51 +08:00
#include "marsio_io.h"
#include "dumpfile_io.h"
struct packet_io
{
2024-04-10 17:50:51 +08:00
enum packet_io_mode mode;
struct marsio_io *marsio;
struct dumpfile_io *dumpfile;
};
2024-03-08 14:51:21 +08:00
struct packet_io *packet_io_new(struct packet_io_options *opts)
{
2024-04-10 17:50:51 +08:00
struct packet_io *packet_io = (struct packet_io *)calloc(1, sizeof(struct packet_io));
if (packet_io == NULL)
{
PACKET_IO_LOG_ERROR("unable to alloc packet io");
return NULL;
}
2024-04-10 17:50:51 +08:00
packet_io->mode = opts->mode;
2024-03-08 14:51:21 +08:00
if (opts->mode == PACKET_IO_MARSIO)
{
2024-04-10 17:50:51 +08:00
packet_io->marsio = marsio_io_new(opts->app_symbol, opts->dev_symbol, opts->cpu_mask, opts->nr_threads);
}
else
{
2024-04-10 17:50:51 +08:00
packet_io->dumpfile = dumpfile_io_new(opts->dumpfile_dir, opts->nr_threads);
}
2024-04-10 17:50:51 +08:00
if (packet_io->marsio == NULL && packet_io->dumpfile == NULL)
{
goto error_out;
}
2024-04-10 17:50:51 +08:00
return packet_io;
error_out:
2024-04-10 17:50:51 +08:00
packet_io_free(packet_io);
return NULL;
}
2024-04-10 17:50:51 +08:00
void packet_io_free(struct packet_io *packet_io)
{
2024-04-10 17:50:51 +08:00
if (packet_io)
{
2024-04-10 17:50:51 +08:00
if (packet_io->mode == PACKET_IO_MARSIO)
{
marsio_io_free(packet_io->marsio);
}
else
{
dumpfile_io_free(packet_io->dumpfile);
}
free(packet_io);
packet_io = NULL;
}
}
2024-04-10 17:50:51 +08:00
struct packet_stat *packet_io_stat(struct packet_io *packet_io)
2024-03-08 14:25:01 +08:00
{
2024-04-10 17:50:51 +08:00
if (packet_io->mode == PACKET_IO_MARSIO)
{
return marsio_io_stat(packet_io->marsio);
}
else
{
return dumpfile_io_stat(packet_io->dumpfile);
}
2024-03-08 14:25:01 +08:00
}
2024-04-10 17:50:51 +08:00
int packet_io_init(struct packet_io *packet_io, uint16_t thr_idx)
{
2024-04-10 17:50:51 +08:00
if (packet_io->mode == PACKET_IO_MARSIO)
{
return marsio_io_init(packet_io->marsio, thr_idx);
}
else
{
return dumpfile_io_init(packet_io->dumpfile, thr_idx);
}
}
2024-04-10 17:50:51 +08:00
int packet_io_ingress(struct packet_io *packet_io, uint16_t thr_idx, struct packet *pkts, int nr_pkts)
{
2024-04-10 17:50:51 +08:00
if (packet_io->mode == PACKET_IO_MARSIO)
{
return marsio_io_ingress(packet_io->marsio, thr_idx, pkts, nr_pkts);
}
else
{
return dumpfile_io_ingress(packet_io->dumpfile, thr_idx, pkts, nr_pkts);
}
}
2024-04-10 17:50:51 +08:00
void packet_io_egress(struct packet_io *packet_io, uint16_t thr_idx, struct packet *pkts, int nr_pkts)
{
2024-04-10 17:50:51 +08:00
if (packet_io->mode == PACKET_IO_MARSIO)
{
marsio_io_egress(packet_io->marsio, thr_idx, pkts, nr_pkts);
}
else
{
dumpfile_io_egress(packet_io->dumpfile, thr_idx, pkts, nr_pkts);
}
}
2024-04-10 17:50:51 +08:00
void packet_io_drop(struct packet_io *packet_io, uint16_t thr_idx, struct packet *pkts, int nr_pkts)
{
2024-04-10 17:50:51 +08:00
if (packet_io->mode == PACKET_IO_MARSIO)
{
marsio_io_drop(packet_io->marsio, thr_idx, pkts, nr_pkts);
}
else
{
dumpfile_io_drop(packet_io->dumpfile, thr_idx, pkts, nr_pkts);
}
}