本文整理汇总了C++中sendall函数的典型用法代码示例。如果您正苦于以下问题:C++ sendall函数的具体用法?C++ sendall怎么用?C++ sendall使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sendall函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetTickCount
VInt
VSocket::Send(const char *buff, const VCard bufflen)
{
//adzm 2010-08-01
m_LastSentTick = GetTickCount();
unsigned int newsize=queuebuffersize+bufflen;
char *buff2;
buff2=(char*)buff;
unsigned int bufflen2=bufflen;
// adzm 2010-09 - flush as soon as we have a full buffer, not if we have exceeded it.
if (newsize >= G_SENDBUFFER)
{
memcpy(queuebuffer+queuebuffersize,buff2,G_SENDBUFFER-queuebuffersize);
if (!sendall(sock,queuebuffer,G_SENDBUFFER,0)) return FALSE;
// vnclog.Print(LL_SOCKERR, VNCLOG("SEND %i\n") ,G_SENDBUFFER);
buff2+=(G_SENDBUFFER-queuebuffersize);
bufflen2-=(G_SENDBUFFER-queuebuffersize);
queuebuffersize=0;
// adzm 2010-09 - flush as soon as we have a full buffer, not if we have exceeded it.
while (bufflen2 >= G_SENDBUFFER)
{
if (!sendall(sock,buff2,G_SENDBUFFER,0)) return false;
// vnclog.Print(LL_SOCKERR, VNCLOG("SEND 1 %i\n") ,G_SENDBUFFER);
buff2+=G_SENDBUFFER;
bufflen2-=G_SENDBUFFER;
}
}
memcpy(queuebuffer+queuebuffersize,buff2,bufflen2);
queuebuffersize+=bufflen2;
if (queuebuffersize > 0) {
if (!sendall(sock,queuebuffer,queuebuffersize,0))
return false;
}
// vnclog.Print(LL_SOCKERR, VNCLOG("SEND 2 %i\n") ,queuebuffersize);
queuebuffersize=0;
return bufflen;
}
示例2: cmc_crawl
int cmc_crawl(int socketha,char collection_inn[], char *extra_in) {
char collection[64];
char extrabuf[512];
int intrespons;
int i;
//toDo bruk strSspy
strncpy(collection,collection_inn,sizeof(collection));
strncpy(extrabuf, extra_in, sizeof(extrabuf));
sendpacked(socketha,cm_crawlcollection,BLDPROTOCOLVERSION, 0, NULL,"");
if(sendall(socketha,&collection, sizeof(collection)) == 0) { perror("sendall"); exit(1); }
if(sendall(socketha,&extrabuf, sizeof(extrabuf)) == 0) { perror("sendall"); exit(1); }
if ((i=recv(socketha, &intrespons, sizeof(intrespons),MSG_WAITALL)) == -1) {
perror("Cant recv respons");
return 0;
}
return 1;
}
示例3: net_socketSSL_flush
int net_socketSSL_flush(net_socketSSL_t* self)
{
assert(self);
int flushed = 1;
if((self->type == NET_SOCKETSSL_TCP_BUFFERED) &&
(self->buffer))
{
flushed = sendall(self, self->buffer, self->len, 0);
self->len = 0;
}
return flushed;
}
示例4: sendToVICC
static ssize_t sendToVICC(struct vicc_ctx *ctx, size_t length, const unsigned char* buffer)
{
ssize_t r;
uint16_t size;
if (!ctx || length > 0xFFFF) {
errno = EINVAL;
return -1;
}
/* send size of message on 2 bytes */
size = htons((uint16_t) length);
r = sendall(ctx->client_sock, (void *) &size, sizeof size);
if (r == sizeof size)
/* send message */
r = sendall(ctx->client_sock, buffer, length);
if (r < 0)
vicc_eject(ctx);
return r;
}
示例5: cmd_download
int cmd_download(int argc, char* argv[])
{
//check if eligible for download
if(localInfo.isServer){
printf("Command Not Avaiable on Server\n");
return EINVAL;
}
if(argc < 3){
printf("Peer ID and Filename required\n");
return EINVAL;
}
printf("ARG COUNT %d\n", argc);
if(argc % 2 == 0){
printf("Provide connection ID and fileName for every host\n");
return EINVAL;
}
int index = 1;
char * filename;
int socketfd;
char message[MESSAGE];
//Loop for every pair [ID, FILENAME]
//send request for file to each of listed hosts
while(index < argc){
socketfd = getSocketFromList(atoi(argv[index]));
if(socketfd == EINVAL){
printf("Upload Failed.\n");
return EINVAL;
}
filename = argv[index + 1];
//REQUEST file from remote host
sprintf(message, "%d %s\n", REQUEST_FILE, filename);
if(sendall(socketfd, message, sizeof(message)) == -1){
perror("UPLOAD: message ");
return -1;
}
index += 2;
}
return 0;
}
示例6: handle_command
/**
* @brief Processes commands from client shell and passes them to server_auth, server_get or server_set.
*
* @param sock The socket connected to the client.
* @param cmd The command received from the client.
* @return Returns 0 on success, 1 otherwise.
*/
int handle_command(int sock, char *cmd)
{
sprintf(log_buffer, "handle_command: Processing command '%s'\n", cmd);
logger(server_log, log_buffer); // replace LOG commands with logger() calls
char buf[MAX_CMD_LEN] = {0};
if(sscanf(cmd, "%s", buf) != 1)
return 0;
else if(strcmp(buf, "AUTH") == 0)
server_auth(cmd);
else if(strcmp(buf, "GET") == 0)
{
gettimeofday(&start_time, NULL);
server_get(cmd);
gettimeofday(&end_time, NULL);
get_processing_time.tv_usec += (end_time.tv_sec - start_time.tv_sec)*1000000L + (end_time.tv_usec - start_time.tv_usec);
fprintf(server_time_log, "get performed in %ld microseconds\n", (end_time.tv_sec - start_time.tv_sec)*1000000L + (end_time.tv_usec - start_time.tv_usec));
}
else if(strcmp(buf, "SET") == 0)
{
gettimeofday(&start_time, NULL);
server_set(cmd);
gettimeofday(&end_time, NULL);
set_processing_time.tv_usec += (end_time.tv_sec - start_time.tv_sec)*1000000L + (end_time.tv_usec - start_time.tv_usec);
fprintf(server_time_log, "storage_set performed in %ld microseconds\n", (end_time.tv_sec - start_time.tv_sec)*1000000L + (end_time.tv_usec - start_time.tv_usec));
}
else
return 1;
// Send back the response to the client.
sendall(sock, cmd, strlen(cmd));
sendall(sock, "\n", 1);
return 0;
}
示例7: main
int main(int argc, char **argv) {
struct addrinfo hints, *res;
struct sockaddr_storage their_addr;
socklen_t addr_size;
char *listenport;
int listenfd, connfd;
char buf[1024];
size_t bytes;
int yes;
listenport = argv[1];
bzero(&hints, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE;
getaddrinfo(NULL, listenport, &hints, &res);
listenfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
bind(listenfd, res->ai_addr, res->ai_addrlen);
listen(listenfd, BACKLOG);
printf("Waiting for connections...\n");
while (1) {
addr_size = sizeof(their_addr);
connfd = accept(listenfd, (struct sockaddr*)&their_addr, &addr_size);
yes = 60;
setsockopt(connfd, SOL_SOCKET, SO_RCVTIMEO, &yes, sizeof(int));
printf("got connection.\n");
if (!fork()) {
close(listenfd);
while ((bytes = recv(connfd, buf, sizeof(buf), 0))) {
buf[bytes] = 0;
sendall(connfd, buf, strlen(buf), 0);
}
close(connfd);
exit(0);
}
close(connfd);
}
freeaddrinfo(res);
close(listenfd);
close(connfd);
return 0;
}
示例8: rComand
int rComand(char dest[], int LotNr,char subname[]) {
int destLen;
int socketha = conectTo(LotNr);
//sender heder
sendpacked(socketha,C_rComand,BLDPROTOCOLVERSION, 0, NULL,subname);
//sender lotnr
sendall(socketha,&LotNr, sizeof(LotNr));
destLen = strlen(dest) +1; // \0
//sender destinasjonsstring lengde
sendall(socketha,&destLen, sizeof(destLen));
//sender destinasjon
sendall(socketha,dest, destLen);
return 1;
}
示例9: cmc_killcrawl
int cmc_killcrawl(int socketha, int port) {
int resp;
sendpacked(socketha, cm_killcrawl, BLDPROTOCOLVERSION, 0, NULL, "");
if (sendall(socketha, &port, sizeof port) == 0) {
perror("killcrawl sendall");
exit(1);
}
if (recv(socketha, &resp, sizeof resp, MSG_WAITALL) == -1) {
perror("killcrawl recv");
return 0;
}
return resp;
}
示例10: bsQuery
int
bsQuery(int *sock, void *data, size_t data_size) {
//printf("Sending %d\n", data_size);
if (sock == 0)
return 0;
if (sendall(*sock, data, data_size) != data_size) {
perror("sendall");
*sock = 0;
return 0;
}
return 1;
}
示例11: memset
char *send_cmd(char *cmd) {
struct addrinfo hints;
struct addrinfo *result, *rp;
int sfd, s, j;
size_t len;
ssize_t nread;
//printf("cmd: %s\n", cmd);
/* Obtain address(es) matching host/port */
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = 0;
s = getaddrinfo(IP, PORT, &hints, &result);
if (s != 0) {
//fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(s));
return "getaddrinfo: fail";
}
for (rp = result; rp != NULL; rp = rp->ai_next) {
sfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
if (sfd == -1)
continue;
if (connect(sfd, rp->ai_addr, rp->ai_addrlen) < 0) {
close(sfd);
continue;
}
break; /* Success */
}
if (rp == NULL) { /* No address succeeded */
return "?Err?";
}
freeaddrinfo(result); /* No longer needed */
/* Send command as message and wait for a response */
len = strlen(cmd);
len++; // include ZERO terminator
if (sendall(sfd, cmd, &len) == -1) {
//fprintf(stderr, "partial/failed send. Only sent %d/%d\n", len, strlen(argv[i]));
return "partial send";
}
nread = recv(sfd, buf, BUF_SIZE, 0);
buf[nread] = 0; // Always terminate
close(sfd);
return buf;
}
示例12: forward_client_to_service
int forward_client_to_service(struct ConnectionState *st) {
char buf[4096];
int r = 1;
int ret = SSL_read(st->ssl, buf, sizeof(buf));
int err = SSL_get_error(st->ssl, ret);
switch (err) {
case SSL_ERROR_NONE:
{
// fcntl(st->service_conn, F_SETFL, 0);
assert(ret > 0);
stats.up_bytes += ret;
int status = sendall(st->service_conn, buf, ret);
log_data(st, buf, ret);
if (status < 0) {
fprintf(stderr, "couldn't forward data to service\n");
cleanup_connection(st);
return 0;
}
// fcntl(st->service_conn, F_SETFL, O_NONBLOCK);
break;
}
case SSL_ERROR_ZERO_RETURN:
case SSL_ERROR_WANT_CONNECT:
case SSL_ERROR_WANT_ACCEPT:
case SSL_ERROR_WANT_X509_LOOKUP:
case SSL_ERROR_SYSCALL:
case SSL_ERROR_SSL:
if (err == SSL_ERROR_SSL) {
extern BIO *bio_err;
if (!bio_err) {
bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
}
ERR_print_errors(bio_err);
} else if (err == SSL_ERROR_SYSCALL) {
// Socket closed
cleanup_connection_after_ssl(st, 1);
return 0;
}
cleanup_connection(st);
r = 0;
break;
case SSL_ERROR_WANT_READ:
case SSL_ERROR_WANT_WRITE:
//fprintf(stderr, "Ignoring recoverable SSL error %d while forwarding to service\n", err);
break;
}
return r;
}
示例13: bbdn_HasSufficientSpace
int bbdn_HasSufficientSpace(int socketha, char subname[]) {
int intrespons = 0;
int len, i;
//sender heder
sendpacked(socketha,bbc_HasSufficientSpace,BLDPROTOCOLVERSION, 0, NULL,"");
//subname
len = strlen(subname) +1;
debug("sending (len %i): \"%s\"",len,subname);
if(sendall(socketha,&len, sizeof(int)) == 0) { perror("sendall subname len"); return 1; }
if(sendall(socketha,subname, len) == 0) { perror("sendall subname"); return 1; }
if ((i=recv(socketha, &intrespons, sizeof(intrespons),MSG_WAITALL)) == -1) {
bperror("Cant recv respons");
return 1;
}
return intrespons;
}
示例14: net_socketSSL_sendall
int net_socketSSL_sendall(net_socketSSL_t* self,
const void* data, int len)
{
assert(self);
assert(data);
int buffered = 0;
if((self->type == NET_SOCKETSSL_TCP_BUFFERED) &&
(self->buffer))
{
buffered = 1;
}
return sendall(self, data, len, buffered);
}
示例15: rGetFileSize
off_t rGetFileSize(char source[], int LotNr,char subname[]) {
int socketha = conectTo(LotNr);
#ifdef DEBUG
printf("rGetFileSize\n");
#endif
int filnamelen;
off_t i;
off_t fileBloks;
//sender heder
sendpacked(socketha,C_rGetSize,BLDPROTOCOLVERSION, 0, NULL,subname);
//sender lotnr
sendall(socketha,&LotNr, sizeof(LotNr));
//sender filnavn lengde
filnamelen = strlen(source) +1; // +1 for \0
sendall(socketha,&filnamelen, sizeof(filnamelen));
//sender hvilken fil vi vil ha
sendall(socketha,source, filnamelen);
//leser inn filstørelsen
if ((i=recv(socketha, &fileBloks, sizeof(fileBloks),MSG_WAITALL)) == -1) {
perror("rGetFileSize: Cant recv fileBloks");
exit(1);
}
return fileBloks;
}