当前位置: 首页>>代码示例>>C++>>正文


C++ UMIN函数代码示例

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


在下文中一共展示了UMIN函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: uwsgi_rados_read_async

static int uwsgi_rados_read_async(struct wsgi_request *wsgi_req, rados_ioctx_t ctx, const char *key, uint64_t off, uint64_t remains, size_t bufsize, int timeout) {
	int ret = -1;
	char *buf = uwsgi_malloc(UMIN(remains, bufsize));

	struct uwsgi_rados_io *urio = &urados.urio[wsgi_req->async_id];
	// increase request counter
	pthread_mutex_lock(&urio->mutex);
	urio->rid++;
	pthread_mutex_unlock(&urio->mutex);

	while(remains > 0) {
		struct uwsgi_rados_cb *urcb = uwsgi_malloc(sizeof(struct uwsgi_rados_cb));
		// map the current request id to the callback
		urcb->rid = urio->rid;
		// map urio to the callback
		urcb->urio = urio;


		rados_completion_t comp;
		if (rados_aio_create_completion(urcb, uwsgi_rados_read_async_cb, NULL, &comp) < 0) {
			free(urcb);
			break;
		}
		// trigger an async read
		if (rados_aio_read(ctx, key, comp, buf, UMIN(remains, bufsize), off) < 0) {
			free(urcb);
			rados_aio_release(comp);
			break;
		}
		// wait for the callback to be executed
		if (uwsgi.wait_read_hook(urio->fds[0], timeout) <= 0) {
			rados_aio_release(comp);
			break;
		}
		char ack = 1;
		if (read(urio->fds[0], &ack, 1) != 1) {
			rados_aio_release(comp);
			uwsgi_error("uwsgi_rados_read_async()/read()");
			break;
		}
		int rlen = -1;	
		if (rados_aio_is_complete_and_cb(comp)) {
			rlen = rados_aio_get_return_value(comp);
		}
		rados_aio_release(comp);
		if (rlen <= 0) break;
		if (uwsgi_response_write_body_do(wsgi_req, buf, rlen)) break;
		remains -= rlen;
		off += rlen;
	}

	free(buf);
	if (remains == 0) ret = 0;

	pthread_mutex_lock(&urio->mutex);
	// increase the counter again
	urio->rid++;
	pthread_mutex_unlock(&urio->mutex);
	return ret;	
}
开发者ID:Nikolo,项目名称:uwsgi,代码行数:60,代码来源:rados.c

示例2: uwsgi_proto_sctp_sendfile

ssize_t uwsgi_proto_sctp_sendfile(struct wsgi_request * wsgi_req) {

        ssize_t len;
        char buf[65536];
        size_t remains = wsgi_req->sendfile_fd_size - wsgi_req->sendfile_fd_pos;

        wsgi_req->sendfile_fd_chunk = 65536;

        if (uwsgi.async > 1) {
                len = read(wsgi_req->sendfile_fd, buf, UMIN(remains, wsgi_req->sendfile_fd_chunk));
                if (len != (int) UMIN(remains, wsgi_req->sendfile_fd_chunk)) {
                        uwsgi_error("read()");
                        return -1;
                }
                wsgi_req->sendfile_fd_pos += len;
                return uwsgi_proto_sctp_write(wsgi_req, buf, len);
        }

        while (remains) {
                len = read(wsgi_req->sendfile_fd, buf, UMIN(remains, wsgi_req->sendfile_fd_chunk));
                if (len != (int) UMIN(remains, wsgi_req->sendfile_fd_chunk)) {
                        uwsgi_error("read()");
                        return -1;
                }
                wsgi_req->sendfile_fd_pos += len;
                len = uwsgi_proto_sctp_write(wsgi_req, buf, len);
                remains = wsgi_req->sendfile_fd_size - wsgi_req->sendfile_fd_pos;
        }

        return wsgi_req->sendfile_fd_pos;

}
开发者ID:bertil-april,项目名称:uwsgi,代码行数:32,代码来源:sctp.c

示例3: socket_to_un_addr

socklen_t socket_to_un_addr(char *socket_name, struct sockaddr_un * sun_addr) {

	size_t len = strlen(socket_name);

	if (len > 102) {
		uwsgi_log("invalid UNIX socket address: %s\n", socket_name);
		uwsgi_nuclear_blast();
	}

	memset(sun_addr, 0, sizeof(struct sockaddr_un));

	sun_addr->sun_family = AF_UNIX;

	// abstract socket
	if (socket_name[0] == '@') {
		memcpy(sun_addr->sun_path + 1, socket_name + 1, UMIN(len - 1, 101));
		len = strlen(socket_name) + 1;
	}
	else if (len > 1 && socket_name[0] == '\\' && socket_name[1] == '0') {
		memcpy(sun_addr->sun_path + 1, socket_name + 2, UMIN(len - 2, 101));
		len = strlen(socket_name + 1) + 1;
	}
	else {
		memcpy(sun_addr->sun_path, socket_name, UMIN(len, 102));
	}

	return sizeof(sun_addr->sun_family) + len;
}
开发者ID:chiwong,项目名称:flask_quickstart,代码行数:28,代码来源:socket.c

示例4: do_mpdamage

/*
 * Lets mob cause unconditional damage to someone. Nasty, use with caution.
 * Also, this is silent, you must show your own damage message...
 *
 * Syntax: mob damage [victim] [min] [max] {kill}
 */
void do_mpdamage(CHAR_DATA * ch, char *argument)
{
    CHAR_DATA *victim = NULL, *victim_next;
    char target[MAX_INPUT_LENGTH], min[MAX_INPUT_LENGTH], max[MAX_INPUT_LENGTH];
    int low, high;
    bool fAll = FALSE, fKill = FALSE;

    argument = one_argument(argument, target);
    argument = one_argument(argument, min);
    argument = one_argument(argument, max);

    if (target[0] == '\0') {
	bug("MpDamage - Bad syntax from vnum %d.",
	    IS_NPC(ch) ? ch->pIndexData->vnum : 0);
	return;
    }
    if (!str_cmp(target, "all"))
	fAll = TRUE;
    else if ((victim = get_char_room(ch, target)) == NULL)
	return;

    if (is_number(min))
	low = atoi(min);
    else {
	bug("MpDamage - Bad damage min vnum %d.",
	    IS_NPC(ch) ? ch->pIndexData->vnum : 0);
	return;
    }
    if (is_number(max))
	high = atoi(max);
    else {
	bug("MpDamage - Bad damage max vnum %d.",
	    IS_NPC(ch) ? ch->pIndexData->vnum : 0);
	return;
    }
    one_argument(argument, target);

    /*
     * If kill parameter is omitted, this command is "safe" and will not
     * kill the victim.
     */

    if (target[0] != '\0')
	fKill = TRUE;
    if (fAll) {
	for (victim = ch->in_room->people; victim; victim = victim_next) {
	    victim_next = victim->next_in_room;
	    if (victim != ch)
		damage(victim, victim,
		       fKill ?
		       number_range(low, high) : UMIN(victim->hit, number_range(low, high)),
		       TYPE_UNDEFINED, DAM_NONE, FALSE);
	}
    } else
	damage(victim, victim,
	       fKill ?
	       number_range(low, high) : UMIN(victim->hit, number_range(low, high)),
	       TYPE_UNDEFINED, DAM_NONE, FALSE);
    return;
}
开发者ID:MikeMayer,项目名称:act-of-war,代码行数:66,代码来源:mob_cmds.c

示例5: fill_combat_roll

void fill_combat_roll(COMBAT_ROLL_BOX *crb, bool defense, int bonus_die_skill)
{
	int roller, roll, temp;

	memset(crb->rolls, 0, MAX_COMBAT_DICE_POOL * sizeof(int));

	temp = (int)(UMIN(MAX_LEVEL, crb->combatant_level) / 50) + 1;
	crb->significant_dice_count = UMIN(MAX_COMBAT_DICE_POOL, temp);

	temp = crb->significant_dice_count + (crb->significant_dice_count / 2) + (defense ? 2 : 0);
	crb->dice_pool = UMIN(MAX_COMBAT_DICE_POOL, temp);

	crb->die_type = defense ? 115 : 125;

	/* Roll the pool of dice.  Any roll over the weapon skill counts as a "botch". */
	crb->botch_count = 0;
	for (roller = 0; roller < crb->dice_pool; roller++) {
		roll = number_range(1, crb->die_type);
		crb->rolls[roller] = (roll <= crb->weapon_skill) ? roll : 0;
		if (roll >= 105 && roll > crb->weapon_skill)
			crb->botch_count++;
	}

	/* Don't count the botches in the insignificant group of dice. */
	/* Accept the possibility of negative count. */
	crb->botch_count -= (crb->dice_pool - crb->significant_dice_count);

	/* Bubble sort is ok here because we are talking about only a few rolls. */
	i_bubble_sort(crb->rolls, crb->dice_pool);

	/* If bonus skill, roll the dice pool (limited to significant count) and allow the
	 * first success greater than the least roll in the significant pool to replace
	 * the least roll.
	 */
	if (bonus_die_skill > 0) {
		for (roller = 0; roller < crb->significant_dice_count; roller++) {
			roll = number_range(1, crb->die_type);
			if (roll <= bonus_die_skill && roll > crb->rolls[crb->significant_dice_count - 1]) {
				crb->rolls[crb->significant_dice_count - 1] = roll;
				crb->bonus_die_success = true;
				break;
			}
		}
	}

	/* Sum up all the significant rolls. */
	crb->total_roll = 0;
	for (roller = 0; roller < crb->significant_dice_count; roller++)
		crb->total_roll += crb->rolls[roller];

	if (crb->combat_rating > 10000)
		crb->total_roll *= 10;
}
开发者ID:codernator,项目名称:creepy-garbanzo,代码行数:53,代码来源:combat_roll.c

示例6: uwsgi_rados_read_sync

static int uwsgi_rados_read_sync(struct wsgi_request *wsgi_req, rados_ioctx_t ctx, const char *key, uint64_t off, uint64_t remains, size_t bufsize) {
	char* buf = uwsgi_malloc(UMIN(remains, bufsize));
	while(remains > 0) {
		int rlen = rados_read(ctx, key, buf, UMIN(remains, bufsize), off);
		if (rlen <= 0) goto end;
		if (uwsgi_response_write_body_do(wsgi_req, buf, rlen)) goto end;
		remains -= rlen;
		off += rlen;
	}
        free(buf);
	return 0;
end:
        free(buf);
        return -1;
}
开发者ID:Nikolo,项目名称:uwsgi,代码行数:15,代码来源:rados.c

示例7: do_wizhelp

// Modified by SinaC 2001
void do_wizhelp( CHAR_DATA *ch, const char *argument ) {
  char buf[MAX_STRING_LENGTH];
  int cmd;
  int col;

  if ( IS_NPC(ch) ) {
    send_to_char("Mobiles can't see immortal command.\n\r",ch);
    return;
  }

  // Added by SinaC 2001
  int lvl = get_trust(ch);
  if ( argument[0] != '\0' && is_number(argument)) {
    lvl = UMIN( atoi(argument), lvl );
  }

  col = 0;
  //for ( cmd = 0; cmd_table[cmd].name[0] != '\0'; cmd++ ) {
  for ( cmd = 0; cmd < MAX_COMMANDS; cmd++ ) {
    if ( cmd_table[cmd].level >= LEVEL_HERO
	 &&   cmd_table[cmd].level <= /*get_trust( ch )*/lvl // Modified by SinaC 2001
	 &&   cmd_table[cmd].show) {
      sprintf( buf, "%-12s", cmd_table[cmd].name );
      send_to_char( buf, ch );
      if ( ++col % 6 == 0 )
	send_to_char( "\n\r", ch );
    }
  }
 
  if ( col % 6 != 0 )
    send_to_char( "\n\r", ch );
  return;
}
开发者ID:SinaC,项目名称:OldMud,代码行数:34,代码来源:interp.C

示例8: spell_sonic_blast

int spell_sonic_blast( int sn, int level, CHAR_DATA *ch, void *vo )
{
    CHAR_DATA *victim       = (CHAR_DATA *) vo;
    static const int        dam_each [ ] =
    {
          0,
          0,   0,   0,   0,   0,          0,   0,   0,   0,   0,
          0,   0,   0,   0,  30,         35,  40,  45,  50,  55,
         60,  65,  70,  75,  80,         82,  84,  86,  88,  90,
         92,  94,  96,  98, 100,        102, 104, 106, 108, 110,
        112, 114, 116, 118, 120,        122, 124, 126, 128, 130,
        132, 134, 136, 138, 140,        142, 144, 146, 148, 150,
        152, 154, 156, 158, 160,        162, 164, 166, 168, 170,
        172, 174, 176, 178, 180,        182, 184, 186, 188, 190,
        192, 194, 196, 198, 200,        202, 204, 206, 208, 210,
        215, 220, 225, 230, 235,        240, 245, 250, 255, 260
    };
    int        dam;

    level    = UMIN( level, sizeof( dam_each ) / sizeof( dam_each[0] ) - 1 );
    level    = UMAX( 0, level );
    dam      = number_range( dam_each[level], dam_each[level] * 6 );

    if ( saves_spell( level, victim ) )
        dam /= 2;
    //damage( ch, victim, dam, sn );
    return dam;   
}
开发者ID:rayhe,项目名称:stormgate,代码行数:28,代码来源:cls_brd.c

示例9: do_blackjack

void do_blackjack(CHAR_DATA *ch,char *argument)
{
    char arg1[MAX_INPUT_LENGTH],arg2[MAX_INPUT_LENGTH];                         
    char buf[MAX_STRING_LENGTH];

	argument = one_argument( argument, arg1 );
	argument = one_argument( argument, arg2 );   

    if( arg1[0] == '\0' )
    {
      send_to_char("You must bet, hit, stand or hand.\n\r",ch);
      return;
    }

    switch( LOWER(arg1[0]) )
    {
      case 'b': place_bet(ch,UMIN(30000,atoi(arg2))); break;
      case 'h': give_card(ch); show_bj_hand(ch,TRUE); check_bj_hand(ch); break;
      case 's': show_bj_hand(ch,TRUE); show_bj_hand(ch,FALSE); break;
      case 'h':
      default: show_bj_hand(ch,TRUE);
    }

    return;
}
开发者ID:Bianary,项目名称:moosehead,代码行数:25,代码来源:gamble.c

示例10: uwsgi_wevdav_manage_put

static int uwsgi_wevdav_manage_put(struct wsgi_request *wsgi_req) {
	char filename[PATH_MAX];
        size_t filename_len = uwsgi_webdav_expand_path(wsgi_req, wsgi_req->path_info, wsgi_req->path_info_len, filename);
        // the collection does not exist, search for the last /
        if (!filename_len) {
		filename_len = uwsgi_webdav_expand_fake_path(wsgi_req, wsgi_req->path_info, wsgi_req->path_info_len, filename);
		if (!filename_len) {
                        uwsgi_response_prepare_headers(wsgi_req, "409 Conflict", 12);
                        return UWSGI_OK;
                }
        }

	int fd = open(filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
	if (fd < 0) {
		uwsgi_403(wsgi_req);
                return UWSGI_OK;
	}

	if (uwsgi_response_prepare_headers(wsgi_req, "201 Created", 11)) goto end;
	
	size_t remains = wsgi_req->post_cl;
	while(remains > 0) {
		ssize_t body_len = 0;
		char *body =  uwsgi_request_body_read(wsgi_req, UMIN(remains, 32768) , &body_len);
		if (!body || body == uwsgi.empty) break;
		if (write(fd, body, body_len) != body_len) goto end;
	}

end:
	close(fd);
	return UWSGI_OK;
}
开发者ID:JuanS,项目名称:uwsgi,代码行数:32,代码来源:webdav.c

示例11: save_npc

int save_npc(Character *ch)
{
    int res = save_character(ch, npc_flags);
    field_map npc_values[] =
    {
        {"nonplayerId", &ch->id, SQL_INT},
        {"shortDescr", &ch->npc->shortDescr, SQL_TEXT},
        {"longDescr", &ch->npc->longDescr, SQL_TEXT},
        {"startPosition", &ch->npc->startPosition, SQL_INT},
        {"areaId", &ch->npc->area->id, SQL_INT},
        {0, 0, 0}
    };

    if (res == 1)
    {

        if (sql_insert_query(npc_values, "nonplayer") != SQL_OK)
        {
            log_data("could not insert player");
            return 0;
        }
    }

    else if (res == 2)
    {

        if (sql_update_query(npc_values, "nonplayer", ch->id) != SQL_OK)
        {
            log_data("could not update character");
            return 0;
        }
    }
    return UMIN(res, 1);
}
开发者ID:ryjen,项目名称:muddled,代码行数:34,代码来源:nonplayer.c

示例12: spell_mass_refresh

/*
 * Mass refresh will refresh every visible character in the room for only
 * 3 more mana than a normal refresh.  It also has an additional 1 to 10
 * movement random bonus on top of the normal refresh.
 */
void spell_mass_refresh(int sn, int level, CHAR_DATA * ch, void *vo, int target)
{
    CHAR_DATA *gch;
    char buf[MAX_STRING_LENGTH];

    for (gch = ch->in_room->people; gch != NULL; gch = gch->next_in_room)
    {
        // If the character can't be seen they can't be refreshed, we don't
        // want this used to sniff out hidden characters.
        if (!can_see(ch, gch))
        {
            continue;
        }

        gch->move = UMIN(gch->move + level + number_range(1, 10), gch->max_move);

        if (gch->max_move == gch->move)
        {
            send_to_char("You feel fully refreshed!\r\n", gch);
        }
        else
        {
            send_to_char("You feel less tired.\r\n", gch);
        }

        if (gch != ch)
        {
            sprintf(buf, "%s has been refreshed.\r\n", gch->name);
            send_to_char(buf, ch);
        }

    }

} // end spell_mass_refresh
开发者ID:blakepell,项目名称:CrimsonSkies,代码行数:39,代码来源:class_healer.c

示例13: check_vnums

bool check_vnums( CHAR_DATA * ch, AREA_DATA * tarea, RENUMBER_AREA * r_area )
{
   int high, low;
   AREA_DATA *area;
   bool proto;

   if( !r_area )
   {
      bug( "%s: NULL r_area!", __func__ );
      return TRUE;
   }

   /*
    * this function assumes all the lows are allways gonna be
    * lower or equal to all the highs .. 
    */
   high = UMAX( r_area->hi_room, UMAX( r_area->hi_obj, r_area->hi_mob ) );
   low = UMIN( r_area->low_room, UMIN( r_area->low_obj, r_area->low_mob ) );

   /*
    * in do_check_vnums they use first_bsort, first_asort but.. i dunno.. 
    */
   area = first_area;
   proto = FALSE;
   while( area )
   {
      if( tarea == area )
         ;
      else if( !( high < area->low_r_vnum || low > area->hi_r_vnum ) ||
               !( high < area->low_o_vnum || low > area->hi_o_vnum ) ||
               !( high < area->low_m_vnum || low > area->hi_m_vnum ) )
      {
         ch_printf( ch, "This operation would overwrite area %s! Use checkvnums first.\r\n", area->filename );
         return TRUE;
      }

      area = area->next;
      if( area == NULL && !proto )
      {
         area = first_build;
         proto = TRUE;
      }
   }
   return FALSE;
}
开发者ID:InfiniteAxis,项目名称:SmaugFUSS,代码行数:45,代码来源:renumber.c

示例14: make_blood

void make_blood( CHAR_DATA * ch )
{
   OBJ_DATA *obj;

   obj = create_object( get_obj_index( OBJ_VNUM_BLOOD ), 0 );
   obj->timer = number_range( 2, 4 );
   obj->value[1] = number_range( 3, UMIN( 5, ch->level ) );
   obj_to_room( obj, ch->in_room );
}
开发者ID:Igdra,项目名称:smaugfuss,代码行数:9,代码来源:makeobjs.c

示例15: connect_to_unix

int connect_to_unix(char *socket_name, int timeout, int async) {

	struct pollfd uwsgi_poll;
	struct sockaddr_un uws_addr;
	socklen_t un_size = sizeof(struct sockaddr_un);

	memset(&uws_addr, 0, sizeof(struct sockaddr_un));

	uws_addr.sun_family = AF_UNIX;

	if (socket_name[0] == '@') {
		un_size = sizeof(uws_addr.sun_family) + strlen(socket_name) + 1;
		memcpy(uws_addr.sun_path + 1, socket_name + 1, UMIN(strlen(socket_name + 1), 101));
	}
	else if (strlen(socket_name) > 1 && socket_name[0] == '\\' && socket_name[1] == '0') {
		un_size = sizeof(uws_addr.sun_family) + strlen(socket_name + 1) + 1;
		memcpy(uws_addr.sun_path + 1, socket_name + 2, UMIN(strlen(socket_name + 2), 101));
	}
	else {
		memcpy(uws_addr.sun_path, socket_name, UMIN(strlen(socket_name), 102));
	}

#if defined(__linux__) && defined(SOCK_NONBLOCK) && !defined(OBSOLETE_LINUX_KERNEL)
	uwsgi_poll.fd = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0);
#else
	uwsgi_poll.fd = socket(AF_UNIX, SOCK_STREAM, 0);
#endif
	if (uwsgi_poll.fd < 0) {
		uwsgi_error("socket()");
		return -1;
	}

	uwsgi_poll.events = POLLIN;

	if (timed_connect(&uwsgi_poll, (const struct sockaddr *) &uws_addr, un_size, timeout, async)) {
		// avoid error storm
		//uwsgi_error("connect()");
		close(uwsgi_poll.fd);
		return -1;
	}

	return uwsgi_poll.fd;

}
开发者ID:chiwong,项目名称:flask_quickstart,代码行数:44,代码来源:socket.c


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