void get_1d_copy_helper<MV,S>::
    do_get (const Teuchos::Ptr<const MV>& mv,
            const Teuchos::ArrayView<S>& vals,
            const size_t ldx,
            EDistribution distribution,
            typename MV::global_ordinal_t indexBase)
    {
      typedef typename MV::local_ordinal_t lo_t;
      typedef typename MV::global_ordinal_t go_t;
      typedef typename MV::global_size_t gs_t;
      typedef typename MV::node_t node_t;

      TEUCHOS_TEST_FOR_EXCEPTION(
        mv.getRawPtr () == NULL, std::invalid_argument,
        "Amesos2::get_1d_copy_helper::do_get(5 args): mv is null.");

      Teuchos::RCP<const Tpetra::Map<lo_t,go_t,node_t> > map
        = Amesos2::Util::getDistributionMap<lo_t,go_t,gs_t,node_t> (distribution,
                                                                    mv->getGlobalLength (),
                                                                    mv->getComm (),
                                                                    indexBase,
                                                                    mv->getMap());

      do_get (mv, vals, ldx, Teuchos::ptrInArg (*map), distribution);
    }
Beispiel #2
0
void on_write(struct ev_loop *loop, struct ev_io *watcher, int revents) 
{
    Request *request = (Request *)watcher;
    RequestLine *request_line = &(request->request_line);
    int fd = watcher->fd;
    char *method = request_line->method;
    char *uri = request_line->uri;
    if (!strncasecmp(method,"GET",MAXLINE)) {
        /* get不区分大小写 */
        do_get(fd, uri);
        ev_io_stop(loop, watcher);
        return;
    }
    else if (!strncasecmp(method,"HEAD",MAXLINE)) {
        do_head(fd, uri);
        ev_io_stop(loop, watcher);
        return;
    }
    else if (!strncasecmp(method,"POST",MAXLINE)) {
        do_post(fd, uri);
        ev_io_stop(loop, watcher);
        return;
    }
    send_error(fd, method, "501","Not Implemented");
    ev_io_stop(loop, watcher);
}
Beispiel #3
0
static void
server_callback (SoupServer *server, SoupMessage *msg,
		 const char *path, GHashTable *query,
		 SoupClientContext *context, gpointer data)
{
	char *file_path;
	SoupMessageHeadersIter iter;
	const char *name, *value;

	g_print ("%s %s HTTP/1.%d\n", msg->method, path,
		 soup_message_get_http_version (msg));
	soup_message_headers_iter_init (&iter, msg->request_headers);
	while (soup_message_headers_iter_next (&iter, &name, &value))
		g_print ("%s: %s\n", name, value);
	if (msg->request_body->length)
		g_print ("%s\n", msg->request_body->data);

	file_path = g_strdup_printf (".%s", path);

	if (msg->method == SOUP_METHOD_GET || msg->method == SOUP_METHOD_HEAD)
		do_get (server, msg, file_path);
	else if (msg->method == SOUP_METHOD_PUT)
		do_put (server, msg, file_path);
	else
		soup_message_set_status (msg, SOUP_STATUS_NOT_IMPLEMENTED);

	g_free (file_path);
	g_print ("  -> %d %s\n\n", msg->status_code, msg->reason_phrase);
}
Beispiel #4
0
int main(int argc, const char **argv)
{
	amqp_connection_state_t conn;
	char *queue = NULL;
	int got_something;

	struct poptOption options[] = {
		INCLUDE_OPTIONS(connect_options),
		{"queue", 'q', POPT_ARG_STRING, &queue, 0,
		 "the queue to consume from", "queue"},
		POPT_AUTOHELP
		{ NULL, 0, 0, NULL, 0 }
	};

	process_all_options(argc, argv, options);

	if (!queue) {
		fprintf(stderr, "queue not specified\n");
		return 1;
	}

	conn = make_connection();
	got_something = do_get(conn, queue);
	close_connection(conn);
	return got_something ? 0 : 2;
}
Beispiel #5
0
int NCDStringIndex_Init (NCDStringIndex *o)
{
    o->entries_size = 0;
    
    if (!Array_Init(o, NCDSTRINGINDEX_INITIAL_CAPACITY)) {
        BLog(BLOG_ERROR, "Array_Init failed");
        goto fail0;
    }
    
    if (!NCDStringIndex__Hash_Init(&o->hash, NCDSTRINGINDEX_INITIAL_HASH_BUCKETS)) {
        BLog(BLOG_ERROR, "NCDStringIndex__Hash_Init failed");
        goto fail1;
    }
    
    for (size_t i = 0; i < B_ARRAY_LENGTH(static_strings); i++) {
        if (do_get(o, static_strings[i], strlen(static_strings[i])) < 0) {
            goto fail2;
        }
    }
    
    DebugObject_Init(&o->d_obj);
    return 1;
    
fail2:
    for (NCD_string_id_t i = 0; i < o->entries_size; i++) {
        free(o->entries[i].str);
    }
    NCDStringIndex__Hash_Free(&o->hash);
fail1:
    Array_Free(o);
fail0:
    return 0;
}
Beispiel #6
0
static void
do_cmd(int client, char *buf)
{
    char *cp = buf+strlen(buf)-1;
    while ((*cp == '\n') || (*cp == '\r')) {
        *cp-- = '\0';  // Remove trailing terminators
    }
    printf("Command: %s\n", buf);
    if (strncmp(buf, "ls", 2) == 0) {
        do_ls(client, buf);
    } else
    if (strncmp(buf, "show_all", 8) == 0) {
        do_show_all(client, buf);
    } else
    if (strncmp(buf, "show", 4) == 0) {
        do_show(client, buf);
    } else
    if (strncmp(buf, "time", 4) == 0) {
        do_time(client, buf);
    } else
    if (strncmp(buf, "get", 3) == 0) {
        do_get(client, buf);
    } else
    if (strncmp(buf, "rm", 2) == 0) {
        do_rm(client, buf);
    } else
    {
        fdprintf(client, "Unknown command: %s\n", buf);
    }
}
Beispiel #7
0
void* func_msg(void* arg)
{
	struct thread_info* args = arg;
//	struct sockaddr_in client;
	int sock = args->sock;
	int read_n, errcnt = 0;
	ftp_rqt request;


//	printf("in thread\n");
//	fprintf(stderr, "sock: %d\n", sock);
	while (true) {

		memset(&request, 0, RQT_LEN);
		read_n = recv(sock, (char*)&request, RQT_LEN, 0);

		if (read_n < 0) {
			errcnt ++;
			if (errcnt > 10)
				break ;
			continue ;
		}
		if (read_n == 0) {
			fprintf(stderr, "quit");
			break ; 
		}

	//	printf("msg: %d; read_n: %d\n", request.type, read_n);

		if (request.type == CMD_CLOSE)
			break;

		else if (request.type == CMD_CD) 
			do_chdir(&request, sock);

		else if (request.type == CMD_MKDIR)
			do_mkdir(&request, sock);

		else if (request.type == CMD_RMDIR)
			do_rmdir(&request, sock);

		else if (request.type == CMD_LS)
			do_lsdir(&request, sock);

		else if (request.type == CMD_GET) {
			do_get(&request, sock);
			break;
		}

		else if (request.type == CMD_PUT) {
			printf("put\n");
			do_put(&request, sock);
			break;
		}

//		send(sock, CONFIRM, strlen(CONFIRM)+1, 0);
	}

	thread_end(args);
}
Beispiel #8
0
    Derived* do_get() override
    {
        if (eos_) {
            return nullptr;
        }

        Derived* sts = nullptr;
        try {
            sts = new Derived();
            *iarchive_ >> *sts;
            archive_has_data_ = true;
        } catch (boost::archive::archive_exception& e) {
            if (e.code ==
                boost::archive::archive_exception::input_stream_error) {
                delete sts;
                if (archive_has_data_ && cycle_ < cycles_) {
                    init();
                    return do_get();
                }
                eos_ = true;
                return nullptr;
            }
            throw;
        }
        return sts;
    }
Beispiel #9
0
NCD_string_id_t NCDStringIndex_GetBin (NCDStringIndex *o, const char *str, size_t str_len)
{
    DebugObject_Access(&o->d_obj);
    ASSERT(str)
    
    return do_get(o, str, str_len);
}
    void get_1d_copy_helper<MV,S>::do_get(const Teuchos::Ptr<const MV>& mv,
					  const Teuchos::ArrayView<S>& vals,
					  const size_t ldx)
    {
      const Teuchos::RCP<const Tpetra::Map<typename MV::local_ordinal_t,
	typename MV::global_ordinal_t,
	typename MV::node_t> > map
	= mv->getMap();
      do_get(mv, vals, ldx, Teuchos::ptrInArg(*map));
    }
Beispiel #11
0
int
respond_to(int cfd, const char *method, int method_len, const char *path, int path_len)
{
  /* we only support GET method for now */
  if (strncasecmp(method, "GET", method_len) == 0) {
    return do_get(cfd, path, path_len);
  } else {
    return do_unimplemented(cfd);
  }
}
boost::shared_ptr<Object const> object_cache<Key, Object>::get(const Key& k, size_type max_cache_size)
{
#ifdef BOOST_HAS_THREADS
   static boost::static_mutex mut = BOOST_STATIC_MUTEX_INIT;

   boost::static_mutex::scoped_lock l(mut);
   if(l)
   {
      return do_get(k, max_cache_size);
   }
   //
   // what do we do if the lock fails?
   // for now just throw, but we should never really get here...
   //
   ::boost::throw_exception(std::runtime_error("Error in thread safety code: could not acquire a lock"));
   return boost::shared_ptr<Object>();
#else
   return do_get(k, max_cache_size);
#endif
}
static void
httpd_callback (SoupServer *server, SoupMessage *msg,
                const char *path, GHashTable *query,
                SoupClientContext *context, gpointer data)
{
  OtTrivialHttpd *self = data;

  if (msg->method == SOUP_METHOD_GET || msg->method == SOUP_METHOD_HEAD)
    do_get (self, server, msg, path, context);
  else
    soup_message_set_status (msg, SOUP_STATUS_NOT_IMPLEMENTED);
}
Beispiel #14
0
// Common function to handle all system calls -
// decode the system call type and call an appropriate handler function.
// Be sure to handle undefined system calls appropriately.
void
syscall(trapframe *tf)
{
	// EAX register holds system call command/flags
	uint32_t cmd = tf->regs.eax;
	switch (cmd & SYS_TYPE) {
  	case SYS_CPUTS:	return do_cputs(tf, cmd);
  	case SYS_PUT: return do_put(tf, cmd);
  	case SYS_GET: return do_get(tf, cmd);
  	case SYS_RET: return do_ret(tf, cmd);
  	default:	return;		// handle as a regular trap
	}
}
Beispiel #15
0
ndnboost::shared_ptr<Object const> object_cache<Key, Object>::get(const Key& k, size_type l_max_cache_size)
{
#ifdef NDNBOOST_HAS_THREADS
   static ndnboost::static_mutex mut = NDNBOOST_STATIC_MUTEX_INIT;

   ndnboost::static_mutex::scoped_lock l(mut);
   if(l)
   {
      return do_get(k, l_max_cache_size);
   }
   //
   // what do we do if the lock fails?
   // for now just throw, but we should never really get here...
   //
   ::ndnboost::throw_exception(std::runtime_error("Error in thread safety code: could not acquire a lock"));
#if defined(NDNBOOST_NO_UNREACHABLE_RETURN_DETECTION) || defined(NDNBOOST_NO_EXCEPTIONS)
   return ndnboost::shared_ptr<Object>();
#endif
#else
   return do_get(k, l_max_cache_size);
#endif
}
Beispiel #16
0
int main (int argc, char *argv[]) {
    if (argc < 2) {
        print_doc(argv[0]);
        return EINVAL;
    }

    if (strncmp(argv[1],"put",3) == 0) {
        if (argc < 4) {
            print_doc(argv[0]);
            return EINVAL;
        }
        const char *key = argv[2];
        const char *src = argv[3];
        return do_put(key, src);
    } else if (strncmp(argv[1], "get", 3) == 0) {
        if (argc < 4) {
            print_doc(argv[0]);
            return EINVAL;
        }
        const char *key = argv[2];
        const char *outpath = argv[3];
        return do_get(key, outpath);
    } else if (strncmp(argv[1], "remove", 6) == 0) {
        if (argc < 3) {
            print_doc(argv[0]);
            return EINVAL;
        }
        const char *key = argv[2];
        return do_remove(key);
    } else if (strncmp(argv[1], "search", 6) == 0) {
        if (argc < 4) {
            print_doc(argv[0]);
            return EINVAL;
        }
        const char *key = argv[2];
        const char *outpath = argv[3];
        return do_search(key, outpath);
    } else if (strncmp(argv[1], "stat", 4) == 0) {
        if (argc < 3) {
            print_doc(argv[0]);
            return EINVAL;
        }
        const char *key = argv[2];
        return do_stat(key);
    } else {
        print_doc(argv[0]);
        return EINVAL;
    }

    return 0;
}
Beispiel #17
0
 istream &istream::get( char &ch ) {
   __lock_it( __i_lock );
   if( ipfx1() ) {
       if( rdbuf()->in_avail() ) {
           ch = (char)(rdbuf()->sgetchar());
       } else {
           do_get( ch );
       }
       isfx();
   } else {
       __last_read_length = 0;
   }
   return( *this );
 }
static void task_waiter(rtems_task_argument arg)
{
  while (true) {
    rtems_bdbuf_buffer *bd = NULL;

    suspend(RTEMS_SELF);

    bd = do_get('W');

    do_rel('W', bd);
  }

  rtems_task_delete(RTEMS_SELF);
}
Beispiel #19
0
int
main (int argc, char *const *argv)
{
  unsigned int error_count = 0;
  struct MHD_Daemon *d;

  gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
#ifdef GCRYCTL_INITIALIZATION_FINISHED
  gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
#endif
  if (0 != curl_global_init (CURL_GLOBAL_ALL))
    {
      fprintf (stderr, "Error: %s\n", strerror (errno));
      return 77;
    }
  load_keys ("host1", ABS_SRCDIR "/host1.crt", ABS_SRCDIR "/host1.key");
  load_keys ("host2", ABS_SRCDIR "/host2.crt", ABS_SRCDIR "/host2.key");
  d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS | MHD_USE_ERROR_LOG,
                        4233,
                        NULL, NULL,
                        &http_ahc, NULL,
                        MHD_OPTION_HTTPS_CERT_CALLBACK, &sni_callback,
                        MHD_OPTION_END);
  if (d == NULL)
    {
      fprintf (stderr, MHD_E_SERVER_INIT);
      return -1;
    }
  if (0 != do_get ("https://host1:4233/"))
    error_count++;
  if (0 != do_get ("https://host2:4233/"))
    error_count++;

  MHD_stop_daemon (d);
  curl_global_cleanup ();
  return (0 != error_count) ? 1 : 0;
}
Beispiel #20
0
/**
 * Process the next incoming request
 *
 * @return status response
 */
status_t process_req() {
    msg_t *msg = malloc(sizeof(msg_t));
    resp_t *resp = NULL;

    if (!EREADDATA(*msg)) {
        debug("Disconnected!\n");
        return DISCON;
    }

    msg->buf[sizeof(msg->buf)-1] = '\0';

    switch (msg->type) {
    case MKDIR:
        resp = do_mkdir(msg);
        break;
    case LIST:
        resp = do_list(msg);
        break;
    case PUT:
        resp = do_put(msg);
        break;
    case GET:
        resp = do_get(msg);
        break;
    case RM:
        resp = do_rm(msg);
        break;
    case RMDIR:
        resp = do_rmdir(msg);
        break;
    case QUIT:
        return EXIT;
    default:
        return ERR;
    }

    if (!resp)
        return ERR;

    ESENDDATA(*resp);

    if (last)
        free(last);

    last = (char *)resp;

    return OK;
}
    void get_1d_copy_helper<MV,S>::do_get(const Teuchos::Ptr<const MV>& mv,
					  const Teuchos::ArrayView<S>& vals,
					  const size_t ldx,
					  EDistribution distribution, typename MV::global_ordinal_t indexBase)
    {
      typedef typename MV::local_ordinal_t lo_t;
      typedef typename MV::global_ordinal_t go_t;
      typedef typename MV::global_size_t gs_t;
      typedef typename MV::node_t node_t;
  
      const Teuchos::RCP<const Tpetra::Map<lo_t,go_t,node_t> > map
	= Amesos2::Util::getDistributionMap<lo_t,go_t,gs_t,node_t>(distribution,
								   mv->getGlobalLength(),
								   mv->getComm(), indexBase);
      do_get(mv, vals, ldx, Teuchos::ptrInArg(*map));
    }
Beispiel #22
0
int main(int argc, char* argv[]){

    char* pstItem;

	if (open_shm((void **)&pstItem, AGENT_SHM_ID, sizeof(ItemList), 0666) < 0){
        open_shm((void**)&pstItem, AGENT_SHM_ID, sizeof(ItemList), 0666|IPC_CREAT);
    }
    do_add(1, 1);
    do_add(1, 1);
    do_add(1, 1);

    int rval;
    do_get(1, &rval);
    fprintf(stderr, "rval=%d", rval);

    return 0;
}
istream _FAR & istream::get(signed char _FAR & c)
{
    if( ipfx1() )
        {
        if( bp->in_avail())
            {
            gcount_ = 1;
            c = bp->sbumpc();
            }
        else
            c = do_get();
        }
    else
        setstate(ios::failbit);

    return *this;
}
Beispiel #24
0
static void
server_callback (SoupServer *server, SoupMessage *msg,
		 const char *path, GHashTable *query,
		 SoupClientContext *context, gpointer data)
{
	SoupMessageHeadersIter iter;

	soup_message_headers_iter_init (&iter, msg->request_headers);


	if (msg->method == SOUP_METHOD_GET || msg->method == SOUP_METHOD_HEAD)
		do_get (server, msg, path);
	else if (msg->method == SOUP_METHOD_PUT)
		do_put (server, msg, path);
	else
		soup_message_set_status (msg, SOUP_STATUS_NOT_IMPLEMENTED);
}
Beispiel #25
0
void run_test(int64_t delay_ns)
{
    for (int i = 0; i <= 25; i++) {
        int64_t start, finish;
        start = get_ns();
        do_get(key, 0);
        finish = get_ns();

        int64_t elapsed = finish - start;
        if (i > 0) {
            printf("%f\n", elapsed / 1e9);
            fflush(stdout);
        }

        do_sleep(delay_ns);
    }
}
//consumer thread
void *requestHandler(void)
{
    while(1) {
        printf("consumer run\n");
        pthread_mutex_lock(&m);
        while(numInBuf == 0) {
            printf("consumer waiting\n");
            pthread_cond_wait(&fill,&m);
        }
        fdInfo *fdinfo;
        fdinfo = do_get();
        printf("request file %s\n", fdinfo->uri);
        pthread_cond_signal(&empty);
        pthread_mutex_unlock(&m);
        requestHandle(fdinfo->fd, fdinfo->method, fdinfo->uri, fdinfo->version);
        Close(fdinfo->fd);
    }
}
Beispiel #27
0
static void
server_callback (SoupServer * server, SoupMessage * msg,
    const char *path, GHashTable * query,
    SoupClientContext * context, gpointer data)
{
  GST_DEBUG ("%s %s HTTP/1.%d", msg->method, path,
      soup_message_get_http_version (msg));
  soup_message_headers_foreach (msg->request_headers, print_header, NULL);
  if (msg->request_body->length)
    GST_DEBUG ("%s", msg->request_body->data);

  if (msg->method == SOUP_METHOD_GET || msg->method == SOUP_METHOD_HEAD)
    do_get (msg, path);
  else
    soup_message_set_status (msg, SOUP_STATUS_NOT_IMPLEMENTED);

  GST_DEBUG ("  -> %d %s", msg->status_code, msg->reason_phrase);
}
    void get_1d_copy_helper<MV,S>::do_get(const Teuchos::Ptr<const MV>& mv,
                                          const Teuchos::ArrayView<S>& vals,
                                          const size_t ldx)
    {
      typedef Tpetra::Map<typename MV::local_ordinal_t,
                          typename MV::global_ordinal_t,
                          typename MV::node_t> map_type;
      TEUCHOS_TEST_FOR_EXCEPTION(
        mv.getRawPtr () == NULL, std::invalid_argument,
        "Amesos2::get_1d_copy_helper::do_get(3 args): mv is null.");

      Teuchos::RCP<const map_type> map = mv->getMap ();
      TEUCHOS_TEST_FOR_EXCEPTION(
        map.is_null (), std::invalid_argument,
        "Amesos2::get_1d_copy_helper::do_get(3 args): mv->getMap() is null.");


      do_get (mv, vals, ldx, Teuchos::ptrInArg (*map), ROOTED); // ROOTED the default here for now
    }
Beispiel #29
0
char *
tty_get( const char *prompt )
{
    if (!batchmode && !no_terminal && my_rl_readline && my_rl_add_history)
    {
        char *line;
        char *buf;

        if (!initialized)
            init_ttyfp();

        last_prompt_len = 0;

        line = my_rl_readline (prompt?prompt:"");

        /* We need to copy it to memory controlled by our malloc
           implementations; further we need to convert an EOF to our
           convention. */
        buf = xmalloc(line? strlen(line)+1:2);
        if (line)
        {
            strcpy (buf, line);
            trim_spaces (buf);
            if (strlen (buf) > 2 )
                my_rl_add_history (line); /* Note that we test BUF but add LINE. */
            free (line);
        }
        else
        {
            buf[0] = CONTROL_D;
            buf[1] = 0;
        }
        return buf;
    }
    else
        return do_get ( prompt, 0 );
}
Beispiel #30
0
 const base& get() const { return do_get() ; }