• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ sendall函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中sendall函数的典型用法代码示例。如果您正苦于以下问题:C++ sendall函数的具体用法?C++ sendall怎么用?C++ sendall使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了sendall函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:copilot-com,项目名称:UltraVNC,代码行数:39,代码来源:vsocket.cpp


示例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;
}
开发者ID:FlavioFalcao,项目名称:enterprise-search,代码行数:22,代码来源:client.c


示例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;
}
开发者ID:jeffboody,项目名称:net,代码行数:13,代码来源:net_socketSSL.c


示例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;
}
开发者ID:12019,项目名称:vsmartcard,代码行数:22,代码来源:vpcd.c


示例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;
}
开发者ID:itsbart,项目名称:FileSharing,代码行数:51,代码来源:proj1.c


示例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;
}
开发者ID:vaibhavvijay,项目名称:ECE-297,代码行数:45,代码来源:server.c


示例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;
}
开发者ID:kjbbb,项目名称:socket_exercises,代码行数:50,代码来源:echoserver-fork.c


示例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;
}
开发者ID:FlavioFalcao,项目名称:enterprise-search,代码行数:23,代码来源:reposetoryNET.c


示例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;
}
开发者ID:FlavioFalcao,项目名称:enterprise-search,代码行数:14,代码来源:client.c


示例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;
}
开发者ID:oiuweirwe,项目名称:enterprise-search,代码行数:14,代码来源:library.c


示例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;
}
开发者ID:nhanh0,项目名称:hah,代码行数:49,代码来源:comms.c


示例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;
}
开发者ID:gvsurenderreddy,项目名称:telex,代码行数:49,代码来源:bronnect.c


示例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;
}
开发者ID:oiuweirwe,项目名称:enterprise-search,代码行数:24,代码来源:bbdnclient.c


示例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);
}
开发者ID:jeffboody,项目名称:net,代码行数:15,代码来源:net_socketSSL.c


示例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;
}
开发者ID:FlavioFalcao,项目名称:enterprise-search,代码行数:36,代码来源:reposetoryNET.c


示例16: sendErrorResponse

int sendErrorResponse( int sock, int code, char* data, int datalen )
{
	char* errorString;

	errorString = (char*)malloc( datalen + 32 );
	memset( errorString, 0, datalen + 32 );
	sprintf( errorString, "E %i ", code );
	errorString[strlen(errorString) + datalen] = '\n';	
	memcpy( errorString + strlen(errorString), data, datalen );

	if ( sendall( sock, errorString, strlen(errorString), 0 ) != strlen(errorString) )
	{
		fprintf( stderr, "The data could not be send to the pc.\n" );
		return -1;
	}
}
开发者ID:jakobwesthoff,项目名称:imageutil,代码行数:16,代码来源:nethelper.c


示例17: cmc_collectionislocked

int
cmc_collectionislocked(int socketha, char *collection_in)
{
	char collection[64];
	int r, i;

	strncpy(collection, collection_in, sizeof(collection));
	sendpacked(socketha, cm_collectionislocked, BLDPROTOCOLVERSION, 0, NULL, "");
	sendall(socketha, &collection, sizeof(collection));

	if ((i=recv(socketha, &r, sizeof(r),MSG_WAITALL)) == -1) {
		return 1;
	}

	return r;
}
开发者ID:FlavioFalcao,项目名称:enterprise-search,代码行数:16,代码来源:client.c


示例18: storage_get

/**
 * @brief performs a basic error check and after everything has passed, passes the information onto server via sendall
 * after the execution of this function, we will have the values found inside the table 
 * @param table name of the table we want to get from
 * @param key name of the key
 * @param record is the struct holding the configuration parameters of everything inside the configuration file 
 * @param conn a pointer to the connection status of the server
 * @return return 0 for success, -1 for failure
 */
int storage_get(const char *table, const char *key, struct storage_record *record, void *conn)
{
	// if we have not Connected, do not execute. Also raise the error
	if (didConnect != 1){
		errno = ERR_CONNECTION_FAIL;
		return -1;
	}
	if (didAuthenticate != 1){
		errno = ERR_NOT_AUTHENTICATED;
		return -1;
	}

	if (table == NULL || conn == NULL ){
		errno = ERR_INVALID_PARAM;
		return -1;
	}

	// parse the values to see if its correct
	if (tablecheck(table) == 1 || keycheck(key) == 1){
		errno = ERR_INVALID_PARAM;
		return -1;
	}

	// Connection is really just a socket file descriptor.
	int sock = (int)conn;

	// Send some data.
	char buf[MAX_CMD_LEN];
	memset(buf, 0, sizeof buf);
	snprintf(buf, sizeof buf, "GET %s %s\n", table, key);
	if (sendall(sock, buf, strlen(buf)) == 0 && recvline(sock, buf, sizeof buf) == 0) {

		if (strcmp("table_fail", buf)== 0){
			errno = ERR_TABLE_NOT_FOUND;
			return -1;		
		}
		else if (strcmp("key_fail", buf)== 0){
			errno = ERR_KEY_NOT_FOUND;
			return -1;		
		}
		strncpy(record->value, buf, sizeof record->value);
		didAuthenticate = 1;
		return 0;
	}

	return -1;
}
开发者ID:khashz,项目名称:ECE---Projects,代码行数:56,代码来源:storage.c


示例19: sendIPLIST

void sendIPLIST()
{	
	if(!localInfo.isServer){
		printf("Only Server Boradcasts IP LIST\n");
		return;
	}

	if(head == NULL){
		//nothing to send
		return;
	}

	printf("Broadcasting IP LIST to peers..\n");

	//buffer that will hold entire connection list from server
	char ipList[MESSAGE];
	char* scanner = ipList;
	int nbytes;

	//add message header
	nbytes = sprintf(scanner, "%d ", ADD_IP_LIST);
	scanner += nbytes;

	struct peer *list = head;

	while(list != NULL){
		nbytes = sprintf(scanner, "%s %s %s ", list->hostname, list->ipaddr, list->port);
		scanner += nbytes;
		list = list->next;
	}

	//tag the end of the buffer
	sprintf(scanner, "EOF EOF EOF");

	//reset pointer over list for sending
	list = head;

	//send IP LIST buffer to every socket listed
	while(list != NULL){
		if(sendall(list->socket, ipList, sizeof(ipList)) == -1){
			perror("sendIPLIST: send ");
			return;
		}
		list = list->next;
	}

}
开发者ID:itsbart,项目名称:FileSharing,代码行数:47,代码来源:proj1.c


示例20: dump_processing

static void dump_processing(int sock)
{
    uint32_t dropped = 0, encoded = 0;
    int im = 0, fl = 0, ex = 0;
    char buf[TC_BUF_LINE];
    int n;

    dropped = tc_get_frames_dropped();
    encoded = tc_get_frames_encoded();
    tc_framebuffer_get_counters(&im, &fl, &ex);

    n = tc_snprintf(buf, sizeof(buf),
                    "E=%lu|D=%lu|im=%i|fl=%i|ex=%i",
                    encoded, dropped, im, fl, ex);
    if (n > 0)
        sendall(sock, buf, n);
}
开发者ID:BackupTheBerlios,项目名称:tcforge,代码行数:17,代码来源:socket.c



注:本文中的sendall函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ sendcmdto_one函数代码示例发布时间:2022-05-30
下一篇:
C++ send_vector函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap