Beispiel #1
0
// helpers
//
static void imap_session_reset(ImapSession *session)
{
	ClientState_T current;

	TRACE(TRACE_DEBUG,"[%p]", session);

	memset(session->tag, 0, sizeof(session->tag));
	memset(session->command, 0, sizeof(session->command));

	session->use_uid = 0;
	session->command_type = 0;
	session->command_state = FALSE;
	session->parser_state = FALSE;
	dbmail_imap_session_args_free(session, FALSE);

	PLOCK(session->lock);
	current = session->state;
	PUNLOCK(session->lock);

	if (current == CLIENTSTATE_AUTHENTICATED)
		session->ci->timeout.tv_sec = server_conf->timeout; 
	else
		session->ci->timeout.tv_sec = server_conf->login_timeout; 

	ci_uncork(session->ci);
	
	return;
}
Beispiel #2
0
void clone_link(WorkPtr work) {
  int r, s;
  int i, j, rootI, rootJ, *index;
  index = work->index;

#ifndef NOAUXINFO

  for(r=work->i_beg; r<work->i_end; r++) {
    i = (index == NULL) ? r : index[r];
    if (IGNORE_SEQ(i)) continue;
    if (seqInfo[i].len<window_len) continue;
    for(s=MAX(r+1,work->j_beg); s<work->j_end; s++) {
      j = (index == NULL) ? s : index[s];
      rootI = mini_find_parent(i);
      rootJ = mini_find_parent(j);
      if ((rootI != rootJ) && !(IS_FLAG(FIX,rootI)&&IS_FLAG(FIX,rootJ) )) 
	if ((strlen(seqID[i].clone)>0) &&
	    (strlen(seqID[j].clone)>0) &&
	    (strcmp(seqID[i].clone,seqID[j].clone)==0)) {
	  make_uniond2(rootI,rootJ,0);
	}
    }
  }

  PLOCK(&find_parent_mutex);
  for(i=0; i<num_seqs; i++) 
    tree[i].cluster = find_parent(i);
  PUNLOCK(&find_parent_mutex);
#endif

}	  
Beispiel #3
0
void imap_cb_read(void *arg)
{
	ImapSession *session = (ImapSession *) arg;

	ci_read_cb(session->ci);

	uint64_t have = p_string_len(session->ci->read_buffer);
	uint64_t need = session->ci->rbuff_size;

	int enough = (need>0?(have >= need):(have >= 0));
	int state;
       
	PLOCK(session->ci->lock);
	state = session->ci->client_state;
	PUNLOCK(session->ci->lock);

	TRACE(TRACE_DEBUG,"state [%d] enough %d: %" PRIu64 "/%" PRIu64 "", state, enough, have, need);

	if (state & CLIENT_ERR) {
		imap_session_bailout(session);
	} else if (state & CLIENT_EOF) {
		ci_cork(session->ci);
		if (enough)
			imap_handle_input(session);
		else
			imap_session_bailout(session);
	} else if (have > 0)
		imap_handle_input(session);
}
Beispiel #4
0
void socket_write_cb(int UNUSED fd, short UNUSED what, void *arg)
#endif
{
	ImapSession *session = (ImapSession *)arg;
	ClientState_T state;
	PLOCK(session->lock);
	state = session->state;
	PUNLOCK(session->lock);
#ifdef DEBUG
	TRACE(TRACE_DEBUG,"[%p] on [%d] state [%d] event:%s%s%s%s", session,
			(int) fd, state,
			(what&EV_TIMEOUT) ? " timeout": "",
			(what&EV_READ)    ? " read":    "",
			(what&EV_WRITE)   ? " write":   "",
			(what&EV_SIGNAL)  ? " signal":  ""
	     );
#endif
	switch(state) {
		case CLIENTSTATE_QUIT_QUEUED:
			break; // ignore
		case CLIENTSTATE_LOGOUT:
			imap_session_bailout(session);
			break;
		case CLIENTSTATE_ERROR:
			imap_handle_abort(session);
			break;
		default:
			ci_write_cb(session->ci);
			break;
	}
	dm_queue_drain();
}
Beispiel #5
0
void merge_pair(WorkPtr work, int rootI, int i, int rootJ, int j, 
		int dir) {
  PLOCK(&invert_mutex);
  short invert;
  invert = (int) (tree[i].orient !=  tree[j].orient) ^ dir;
  PUNLOCK(&invert_mutex);
  if (dump_file != NULL) {
    PLOCK(&dump_mutex);
    fprintf(dump_file,"%d %d %d\n",i,j,dir);
    fflush(dump_file);
    PUNLOCK(&dump_mutex);
  }
  make_uniond2(rootI,rootJ,invert);
  total_matches++;
  tree[i].match = j;
  if (tree[j].match==-1) {
    tree[j].match = i;
  }
}
Beispiel #6
0
void MergeSlaveClusterTable(int32_t *buffer, int rlen) {
  // Get the slave's cluster table and add to ours
  int i, id,  rep, rep_root, last;
  int q;
  assert(rlen%MPIBUFRECSZ==0);
  assert(rlen<MPIBUFRECSZ*num_seqs);
  last = -1;
  for(i=0; i<rlen; ) {
    id = buffer[i];
    i++;
    rep= buffer[i];
    i++;
#ifdef MPIORIENT
    int witness, orient;
    witness = buffer[i];
    i++;
    orient = buffer[i];
    i++;
#endif
    PLOCK(&write_union_mutex);
    PLOCK(&find_parent_mutex);
    if (last != rep) {
      last = rep;
      rep_root = find_parent(rep);
    }
    id = find_parent(id);
    if (id == rep_root) {
      PUNLOCK(&find_parent_mutex);
      PUNLOCK(&write_union_mutex);
      continue;
    }
    // if (orient) invert_orientation(j);
    q = tree[rep_root].last;
    tree[q].next = id;
    tree[rep_root].last = tree[id].last;
    tree[id].cluster = rep_root;
    if (IS_FLAG(FIX,id)) SET_FLAG(FIX,rep_root);
    assert(tree[tree[rep_root].last].next<0);
    PUNLOCK(&write_union_mutex);
    PUNLOCK(&find_parent_mutex);
  }
}
Beispiel #7
0
void complete_pairwise_cluster(WorkPtr work, int i, int * candidates, int num_cands) {
	int  s, limit;
	int j, rootI, rootJ;

	int num_mat_pos, num_mat_rc;

	if (clonelink) clone_link(work);
		
	if (IGNORE_SEQ(i)) return;
	if (seqInfo[i].len<window_len) return;

	set_up_word_table(work, i);

	for(s=0; s<num_cands; s++) {
		j = candidates[s];
        //printf("    Candidated %d\n",j);
		rootI = mini_find_parent(i);
		rootJ = mini_find_parent(j);
		assert(i<num_seqs);
		if ((rootI != rootJ) && !(IS_FLAG(FIX,rootI)&&IS_FLAG(FIX,rootJ) )) { 
			// only try to cluster if not already clustered
			// and both are not fixed lcusters
			NUM_num_matches++;
			limit = seqInfo[j].len/BASESPERELT-1;

			check_heuristics(i,j,limit,&num_mat_pos,&num_mat_rc);

			if( (num_mat_pos >= NM_threshold) &&  
			   (!IGNORE_SEQ(j)) &&
			   (d2(work,i,j,0)<=theta)) {
				merge_pair(work,rootI,i,rootJ,j,0);
			};

			if ( rc_check &&   
				(num_mat_rc >= NM_threshold)&& 
				(!IGNORE_SEQ(j)) &&
				(d2(work,i,j,1)<=theta)){
				merge_pair(work,rootI,i,rootJ,j,1);
			}
 
		}
	}
	clear_word_table(work,i);
	PLOCK(&find_parent_mutex);
	for(s=0; s<num_cands; s++) 
		tree[candidates[s]].cluster = find_parent(candidates[s]);
	PUNLOCK(&find_parent_mutex);

}
Beispiel #8
0
void do_pairwise_cluster(WorkPtr work) {
  int r, s, limit;
  int i, j, rootI, rootJ, *index,k;
  uint16_t w0;
  int num_mat_pos, num_mat_rc,invert, samp_pos, samp_rc;

  index = work->index;
  if (clonelink) clone_link(work);
  //printf("Slave %d-t%d here ib=%d ie=%d;  jb=%d je=%d,\n",
  // myid,work->thread_num,work->i_beg,work->i_end,work->j_beg,work->j_end);
  for(r=work->i_beg; r<work->i_end; r++) {
    i = (index == NULL) ? r : index[r];
    //printf("%d %ld %ld %d\n",i,data,seq[i].seq,seq[i].len);
    if (IGNORE_SEQ(i)) continue;
    if (seqInfo[i].len<window_len) continue;
    set_up_word_table(work, i);
    for(s=MAX(r+1,work->j_beg); s<work->j_end; s++) {
      j = (index == NULL) ? s : index[s];
      rootI = mini_find_parent(i);
      rootJ = mini_find_parent(j);
      if ((rootI != rootJ) && !(IS_FLAG(FIX,rootI)&&IS_FLAG(FIX,rootJ) )) { 
        // only try to cluster if not already clustered
        // and both are not fixed lcusters
	num_mat_pos=num_mat_rc=samp_pos=samp_rc=0;
	NUM_num_matches++;
	limit = seqInfo[j].len/BASESPERELT-1;
	for(k=1; k < limit ;k=k+2) {
	  if (work->tableP[seq[j][k]]) samp_pos ++; 
	  if (work->tableR[seq[j][k]]) samp_rc ++;
	}
	if ((samp_pos<=2) && (samp_rc<= 2) )
	  samp_pos=samp_rc=0;
	else
	  for(k=0; k < limit;k=k+2) {
	    w0  =  seq[j][k];
	    if (work->tableP[w0]) samp_pos++;
	    if (work->tableR[w0]) samp_rc++;
	  }
	if (samp_pos >sample_thresh)
	  num_mat_pos = tv_heuristic_pos(work,i,j);
	if (samp_rc > sample_thresh) 
	  num_mat_rc = tv_heuristic_rc(work,i,j);
	if( (num_mat_pos >= NM_threshold) &&  
            (!IGNORE_SEQ(j)) &&
            (dist(work,i,j,0)<=theta)) {
	  PLOCK(&invert_mutex);
	  invert = (int) (tree[i].orient !=  tree[j].orient);
          PUNLOCK(&invert_mutex);
          if (dump_file != NULL) {
	    PLOCK(&dump_mutex);
	    fprintf(dump_file,"%d: %d %d %d\n",
		    work->thread_num,i,j,1);
	    fflush(dump_file);
	    PUNLOCK(&dump_mutex);
	  }
	  make_uniond2(rootI,rootJ,invert);
	  total_matches++;
	  tree[i].match = j;
          if (tree[j].match==-1) {
	    tree[j].match = i;
	  }
	};
	if ( rc_check &&   
             (num_mat_rc >= NM_threshold)&& 
             (!IGNORE_SEQ(j)) &&
	     (dist(work,i,j,1)<=theta)){
	  PLOCK(&invert_mutex);
	  invert = (tree[i].orient==tree[j].orient);
	  PUNLOCK(&invert_mutex);
	  if (dump_file != NULL) {
	    PLOCK(&dump_mutex);
	    fprintf(dump_file,"%d: %d %d %d\n",
		    work->thread_num,i,j,-1);
	    fflush(dump_file);
	    PUNLOCK(&dump_mutex);
	  }
	  make_uniond2(rootI,rootJ,invert);
	  total_matches++;
	  tree[i].match = j;
	  if (tree[j].match==-1) {
	    tree[j].match = i;
	  }
	} 
      }
    }
    clear_word_table(work,i);
  }
  PLOCK(&find_parent_mutex);
  for(i=0; i<num_seqs; i++) 
    tree[i].cluster = find_parent(i);
  PUNLOCK(&find_parent_mutex);

}