本文整理汇总了C++中recv_all函数的典型用法代码示例。如果您正苦于以下问题:C++ recv_all函数的具体用法?C++ recv_all怎么用?C++ recv_all使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了recv_all函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: receive_input
/**
* Receive input buffer, convert to Stream object
*
* @return SUCCESS on success, else, -1 on error
*/
ssize_t receive_input(void) {
ssize_t res;
Stream tmp;
// recv Input type and size
res = recv_all((char *)&tmp, sizeof(tmp));
if (res != sizeof(tmp)) {
_terminate(ERRNO_RECV);
}
// check for invalid INPUT_TYPE
if (memcmp(INPUT_TYPE_PLAIN, (const char *)tmp.type, sizeof(INPUT_TYPE_PLAIN)) &&
memcmp(INPUT_TYPE_SERIALIZED, (const char *)tmp.type, sizeof(INPUT_TYPE_SERIALIZED))) {
return -1;
}
in = malloc(sizeof(tmp) + tmp.size);
MALLOC_OK(in);
in->size = tmp.size;
cgc_memcpy(in->type, tmp.type, sizeof(INPUT_TYPE_SERIALIZED));
res = recv_all(in->content, in->size);
if (res != in->size) {
_terminate(ERRNO_RECV);
}
return SUCCESS;
}
示例2: client_recv_frame
/* post a frame to the wire */
int client_recv_frame(SOCKET MySock, void * buffer, int maxlength)
{
int nret;
unsigned short len;
/* read a 2 byte short indicating size of frame to read */
nret = recv_all(MySock, (char *)&len, sizeof(unsigned short));
len = ntohs(len);
/* do the standard error checking */
if (nret == SOCKET_ERROR)
{
printf("Size receive corrupt\n");
}
/* sanity check for the length value */
if (len > maxlength)
{
printf("Read len is too large\n");
closesocket(MySock);
WSACleanup();
exit(1);
}
/* read the actual frame into our buffer */
//printf("Will read: %d (was %d) from wire\n", len, htons(len));
nret = recv_all(MySock, (char *)buffer, len);
return nret;
}
示例3: get_info_spectate
static bool get_info_spectate(netplay_t *handle)
{
if (!send_nickname(handle, handle->fd))
{
RARCH_ERR("Failed to send nickname to host.\n");
return false;
}
if (!get_nickname(handle, handle->fd))
{
RARCH_ERR("Failed to receive nickname from host.\n");
return false;
}
char msg[512];
snprintf(msg, sizeof(msg), "Connected to \"%s\"", handle->other_nick);
msg_queue_push(g_extern.msg_queue, msg, 1, 180);
RARCH_LOG("%s\n", msg);
uint32_t header[4];
if (!recv_all(handle->fd, header, sizeof(header)))
{
RARCH_ERR("Cannot get header from host.\n");
return false;
}
size_t save_state_size = pretro_serialize_size();
if (!bsv_parse_header(header, implementation_magic_value()))
{
RARCH_ERR("Received invalid BSV header from host.\n");
return false;
}
void *buf = malloc(save_state_size);
if (!buf)
return false;
size_t size = save_state_size;
if (!recv_all(handle->fd, buf, size))
{
RARCH_ERR("Failed to receive save state from host.\n");
free(buf);
return false;
}
bool ret = true;
if (save_state_size)
ret = pretro_unserialize(buf, save_state_size);
free(buf);
return ret;
}
示例4: netplay_get_cmd
static bool netplay_get_cmd(netplay_t *handle)
{
uint32_t cmd;
if (!recv_all(handle->fd, &cmd, sizeof(cmd)))
return false;
cmd = ntohl(cmd);
size_t cmd_size = cmd & 0xffff;
cmd = cmd >> 16;
switch (cmd)
{
case NETPLAY_CMD_FLIP_PLAYERS:
{
if (cmd_size != sizeof(uint32_t))
{
RARCH_ERR("CMD_FLIP_PLAYERS has unexpected command size.\n");
return netplay_cmd_nak(handle);
}
uint32_t flip_frame;
if (!recv_all(handle->fd, &flip_frame, sizeof(flip_frame)))
{
RARCH_ERR("Failed to receive CMD_FLIP_PLAYERS argument.\n");
return netplay_cmd_nak(handle);
}
flip_frame = ntohl(flip_frame);
if (flip_frame < handle->flip_frame)
{
RARCH_ERR("Host asked us to flip players in the past. Not possible ...\n");
return netplay_cmd_nak(handle);
}
handle->flip ^= true;
handle->flip_frame = flip_frame;
RARCH_LOG("Netplay players are flipped.\n");
msg_queue_push(g_extern.msg_queue, "Netplay players are flipped.", 1, 180);
return netplay_cmd_ack(handle);
}
default:
RARCH_ERR("Unknown netplay command received.\n");
return netplay_cmd_nak(handle);
}
}
示例5: main
int main(int argc, char const *argv[])
{
char *ip, *port;
get_input(argc, argv, &ip, &port);
printf("IP = %s\n", ip);
printf("Port = %s\n", port);
int sock;
sock = create_socket(SOCK_DGRAM, ip);
/* PROTOTIPO de como ENVIA mensagens */
char msg[BUF_SIZE];
strcat(msg, "GET /index.html HTTP/1.1\r\nHost: ");
strcat(msg, ip);
strcat(msg, "\r\n\r\n");
print_request(msg);
send_all(sock, msg);
/* PROTOTIPO de como RECEBE mensagens */
// int recv(int sockfd, void *buf, int len, int flags);
char *buff;
size_t by_recv;
by_recv = recv_all(sock, &buff, BUF_SIZE);
print_response(buff);
return 0;
}
示例6: transaction_recv_refund
// recv refund details
// success: SUCCESS
// failure: ERRNO_MP_ALLOC, ERRNO_MP_RECV
int transaction_recv_refund(packet_data_refund_t ** pdr) {
// create memory for refund data
ALLOC(sizeof(packet_data_refund_t), 0, (void **)pdr);
if(sizeof(packet_data_refund_t) != recv_all((char *)*pdr, sizeof(packet_data_refund_t))) {return ERRNO_MP_RECV;}
return SUCCESS;
}
示例7: transaction_recv_history
// recv history details
// success: SUCCESS
// failure: ERRNO_MP_ALLOC, ERRNO_MP_RECV
int transaction_recv_history(packet_data_history_t ** pdh) {
// create memory for history data
ALLOC(sizeof(packet_data_history_t), 0, (void **)pdh);
if(sizeof(packet_data_history_t) != recv_all((char *)*pdh, sizeof(packet_data_history_t))) {return ERRNO_MP_RECV;}
return SUCCESS;
}
示例8: transaction_recv_recharge
// recv recharge details
// success: SUCCESS
// failure: ERRNO_MP_ALLOC, ERRNO_MP_RECV
int transaction_recv_recharge(packet_data_recharge_t ** pdr) {
// create memory for recharge data + vendor
ALLOC(sizeof(packet_data_recharge_t), 0, (void **)pdr);
// read recharge data and vendor data (except vendor_location)
if(10 != recv_all((char *)*pdr, 10)) {return ERRNO_MP_RECV;}
uint32_t vls = (*pdr)->v.vendor_location_sz;
if(vls == 0) {return ERRNO_MP_RECV;}
// create memory for vendor_location char array
ALLOC(vls, 0, (void **)&((*pdr)->v.vendor_location));
// read vendor_location (size is in previous read)
if(vls != recv_all((char *)(*pdr)->v.vendor_location, vls)) {return ERRNO_MP_RECV;}
return SUCCESS;
}
示例9: transaction_recv_issue
// recv issue details
// success: SUCCESS
// failure: ERRNO_MP_ALLOC, ERRNO_MP_RECV
int transaction_recv_issue(packet_data_issue_t ** pdi) {
// create memory for issue data
ALLOC(sizeof(packet_data_issue_t), 0, (void **)pdi);
if(sizeof(packet_data_issue_t) != recv_all((char *)*pdi, sizeof(packet_data_issue_t))) {return ERRNO_MP_RECV;}
return SUCCESS;
}
示例10: run_pp_server
static
void run_pp_server(psdapl_con_info_t *ci)
{
char *buf = malloc(arg_maxmsize);
int msgsize;
while (1) {
msgsize = recv_all(ci, buf);
if (DEBUG_MESSAGES) {
static int allcount = 0;
allcount ++;
printf("received: msgsize:%u %s\n", msgsize, buf + sizeof(unsigned));
sprintf(buf + sizeof(unsigned), "ServerRet#%d", allcount);
printf("Send: %s\n", buf + sizeof(unsigned));
}
send_all(ci, buf, msgsize);
if (msgsize <= 0) break;
}
if (msgsize == 0) {
printf("receive EOF\n");
} else {
printf("receive error : %s\n", strerror(-msgsize));
}
}
示例11: transaction_recv_purchase
// recv purchase details
// success: SUCCESS
// failure: ERRNO_MP_ALLOC, ERRNO_MP_RECV
int transaction_recv_purchase(packet_data_purchase_t ** pdp) {
// create memory for purchase data + vendor
ALLOC(sizeof(packet_data_purchase_t), 0, (void **)pdp);
// cgc_read purchase data and vendor data (except vendor_location)
if(14 != recv_all((char *)*pdp, 14)) {return ERRNO_MP_RECV;}
uint32_t vls = (*pdp)->v.vendor_location_sz;
if(vls == 0) {return ERRNO_MP_RECV;}
// create memory for vendor_location char array
ALLOC(vls, 0, (void **)&((*pdp)->v.vendor_location));
// cgc_read vendor_location (size is in previous cgc_read)
if(vls != recv_all((char *)(*pdp)->v.vendor_location, vls)) {return ERRNO_MP_RECV;}
return SUCCESS;
}
示例12: run_pp_c
static
int run_pp_c(psdapl_con_info_t *ci, unsigned msgsize, unsigned loops)
{
unsigned cnt;
if (msgsize < sizeof(unsigned)) msgsize = sizeof(unsigned);
char *buf = malloc(msgsize);
*((unsigned *)buf) = msgsize;
for (cnt = 0; cnt < loops; cnt++) {
if (DEBUG_MESSAGES) {
sprintf(buf + sizeof(unsigned), "C2S#%d", cnt);
printf("Send: %s\n", buf + sizeof(unsigned));
}
send_all(ci, buf, msgsize);
recv_all(ci, buf);
if (DEBUG_MESSAGES) {
printf("received: %s\n", buf + sizeof(unsigned));
}
}
free(buf);
return 0;
}
示例13: main
int
main(int argc, char **argv)
{
int sendfd, recvfd;
const int on = 1;
socklen_t salen;
struct sockaddr *sasend, *sarecv;
if (argc != 3)
err_quit("usage: sendrecv <IP-multicast-address> <port#>");
sendfd = Udp_client(argv[1], argv[2], (void **) &sasend, &salen);
recvfd = Socket(sasend->sa_family, SOCK_DGRAM, 0);
Setsockopt(recvfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
sarecv = Malloc(salen);
memcpy(sarecv, sasend, salen);
Bind(recvfd, sarecv, salen);
Mcast_join(recvfd, sasend, salen, NULL, 0);
Mcast_set_loop(sendfd, 0);
if (Fork() == 0)
recv_all(recvfd, salen); /* child -> receives */
send_all(sendfd, sasend, salen); /* parent -> sends */
}
示例14: bg_traffic_thread
static void bg_traffic_thread(SInfo *info)
{
static const int data_len = 10;
char sbuffer[data_len + 1] = "dummydata_";
char rbuffer[data_len + 1];
int scount, rtotal = 0;
info->setSenderThreadId(ThisThread::get_id());
for (;;) {
if (!info->available()) {
(void)handle_nsapi_size_or_error(__func__, rtotal);
break;
}
sbuffer[data_len - 1] = 'A' + (rand() % 26);
scount = info->socket().send(sbuffer, data_len);
rtotal = recv_all(rbuffer, data_len, info);
if (scount != rtotal || (strcmp(sbuffer, rbuffer) != 0)) {
info->setUnavailable();
tr_err("Background received data does not match to sent data");
tr_err("Background sent: \"%s\"", sbuffer);
tr_err("Background received: \"%s\"", rbuffer);
}
wait_ms(10);
}
}
示例15: netplay_get_response
static bool netplay_get_response(netplay_t *handle)
{
uint32_t response;
if (!recv_all(handle->fd, &response, sizeof(response)))
return false;
return ntohl(response) == NETPLAY_CMD_ACK;
}