debug_ip("in dispatcher callback, what: %d, fd: %d", (gint)what, fd);
- switch (what) {
- case EV_TIMEOUT:
+ if ((what & EV_TIMEOUT) != 0) {
if (d->err_callback) {
err = g_error_new (G_DISPATCHER_ERROR, ETIMEDOUT, "IO timeout");
d->err_callback (err, d->user_data);
}
- break;
- case EV_WRITE:
+ }
+ else if ((what & EV_READ) != 0) {
+ read_buffers (fd, d, FALSE);
+ }
+ else if ((what & EV_WRITE) != 0) {
/* No data to write, disable further EV_WRITE to this fd */
if (d->in_sendfile) {
sendfile_callback (d);
write_buffers (fd, d, TRUE);
}
}
- break;
- case EV_READ:
- read_buffers (fd, d, FALSE);
- break;
}
}
stat_file_t *file;
struct bayes_statfile_data *statfiles;
guint32 statfiles_num;
- guint64 learned_tokens;
+ guint64 learned_tokens;
+ gsize max_tokens;
};
static gboolean
cd->learned_tokens ++;
}
+ if (cd->max_tokens != 0 && cd->learned_tokens > cd->max_tokens) {
+ /* Stop learning on max tokens */
+ return TRUE;
+ }
return FALSE;
}
}
}
+ cd->learned_tokens ++;
+ if (cd->max_tokens != 0 && cd->learned_tokens > cd->max_tokens) {
+ /* Stop classifying on max tokens */
+ return TRUE;
+ }
+
return FALSE;
}
{
struct bayes_callback_data data;
gchar *value;
- gint nodes, minnodes, i = 0, cnt, best_num = 0;
+ gint nodes, i = 0, cnt, best_num = 0;
+ gsize minnodes;
guint64 rev, total_learns = 0;
double best = 0;
struct statfile *st;
data.now = time (NULL);
data.ctx = ctx;
+ data.learned_tokens = 0;
+ if (ctx->cfg->opts && (value = g_hash_table_lookup (ctx->cfg->opts, "max_tokens")) != NULL) {
+ minnodes = parse_limit (value);
+ data.max_tokens = minnodes;
+ }
+ else {
+ data.max_tokens = 0;
+ }
+
while (cur) {
/* Select statfile to classify */
st = cur->data;
gboolean in_class, double *sum, double multiplier, GError **err)
{
struct bayes_callback_data data;
- char *value;
- int nodes, minnodes;
+ gchar *value;
+ gint nodes;
+ gsize minnodes;
struct statfile *st, *sel_st = NULL;
stat_file_t *to_learn;
GList *cur;
bayes_error_quark(), /* error domain */
1, /* error code */
"message contains too few tokens: %d, while min is %d",
- nodes, minnodes);
+ nodes, (int)minnodes);
return FALSE;
}
}
data.now = time (NULL);
data.ctx = ctx;
data.learned_tokens = 0;
+ data.learned_tokens = 0;
+ if (ctx->cfg->opts && (value = g_hash_table_lookup (ctx->cfg->opts, "max_tokens")) != NULL) {
+ minnodes = parse_limit (value);
+ data.max_tokens = minnodes;
+ }
+ else {
+ data.max_tokens = 0;
+ }
cur = ctx->cfg->statfiles;
while (cur) {
/* Select statfile to learn */
{
struct bayes_callback_data data;
gchar *value;
- gint nodes, minnodes;
+ gint nodes;
+ gsize minnodes;
struct statfile *st;
stat_file_t *file;
GList *cur;
bayes_error_quark(), /* error domain */
1, /* error code */
"message contains too few tokens: %d, while min is %d",
- nodes, minnodes);
+ nodes, (int)minnodes);
return FALSE;
}
}
data.now = time (NULL);
data.ctx = ctx;
+ data.learned_tokens = 0;
+ if (ctx->cfg->opts && (value = g_hash_table_lookup (ctx->cfg->opts, "max_tokens")) != NULL) {
+ minnodes = parse_limit (value);
+ data.max_tokens = minnodes;
+ }
+ else {
+ data.max_tokens = 0;
+ }
+
while (cur) {
/* Select statfiles to learn */
st = cur->data;
/* Init classifiers options */
register_classifier_opt ("bayes", "min_tokens");
register_classifier_opt ("winnow", "min_tokens");
+ register_classifier_opt ("bayes", "max_tokens");
+ register_classifier_opt ("winnow", "max_tokens");
register_classifier_opt ("winnow", "learn_threshold");
/* Pre-init of cache */