Пример #1
0
svn_error_t *
svn_fs_hotcopy2(const char *src_path, const char *dst_path,
                svn_boolean_t clean, svn_boolean_t incremental,
                svn_cancel_func_t cancel_func, void *cancel_baton,
                apr_pool_t *scratch_pool)
{
  fs_library_vtable_t *vtable;
  const char *src_fs_type;
  svn_fs_t *src_fs;
  svn_fs_t *dst_fs;
  const char *dst_fs_type;
  svn_node_kind_t dst_kind;

  if (strcmp(src_path, dst_path) == 0)
    return svn_error_create(SVN_ERR_INCORRECT_PARAMS, NULL,
                             _("Hotcopy source and destination are equal"));

  SVN_ERR(svn_fs_type(&src_fs_type, src_path, scratch_pool));
  SVN_ERR(get_library_vtable(&vtable, src_fs_type, scratch_pool));
  src_fs = fs_new(NULL, scratch_pool);
  dst_fs = fs_new(NULL, scratch_pool);

  SVN_ERR(svn_io_check_path(dst_path, &dst_kind, scratch_pool));
  if (dst_kind == svn_node_file)
    return svn_error_createf(SVN_ERR_NODE_UNEXPECTED_KIND, NULL,
                             _("'%s' already exists and is a file"),
                             svn_dirent_local_style(dst_path,
                                                    scratch_pool));
  if (dst_kind == svn_node_unknown)
    return svn_error_createf(SVN_ERR_NODE_UNEXPECTED_KIND, NULL,
                             _("'%s' already exists and has an unknown "
                               "node kind"),
                             svn_dirent_local_style(dst_path,
                                                    scratch_pool));
  if (dst_kind == svn_node_dir)
    {
      svn_node_kind_t type_file_kind;

      SVN_ERR(svn_io_check_path(svn_dirent_join(dst_path,
                                                FS_TYPE_FILENAME,
                                                scratch_pool),
                                &type_file_kind, scratch_pool));
      if (type_file_kind != svn_node_none)
        {
          SVN_ERR(svn_fs_type(&dst_fs_type, dst_path, scratch_pool));
          if (strcmp(src_fs_type, dst_fs_type) != 0)
            return svn_error_createf(
                     SVN_ERR_ILLEGAL_TARGET, NULL,
                     _("The filesystem type of the hotcopy source "
                       "('%s') does not match the filesystem "
                       "type of the hotcopy destination ('%s')"),
                     src_fs_type, dst_fs_type);
        }
    }

  SVN_ERR(vtable->hotcopy(src_fs, dst_fs, src_path, dst_path, clean,
                          incremental, cancel_func, cancel_baton,
                          scratch_pool));
  return svn_error_trace(write_fs_type(dst_path, src_fs_type, scratch_pool));
}
Пример #2
0
svn_error_t *
svn_fs_pack(const char *path,
            svn_fs_pack_notify_t notify_func,
            void *notify_baton,
            svn_cancel_func_t cancel_func,
            void *cancel_baton,
            apr_pool_t *pool)
{
  svn_error_t *err;
  svn_error_t *err2;
  fs_library_vtable_t *vtable;
  svn_fs_t *fs;

  SVN_ERR(fs_library_vtable(&vtable, path, pool));
  fs = fs_new(NULL, pool);
  SVN_ERR(acquire_fs_mutex());
  err = vtable->pack_fs(fs, path, notify_func, notify_baton,
                        cancel_func, cancel_baton, pool);
  err2 = release_fs_mutex();
  if (err)
    {
      svn_error_clear(err2);
      return svn_error_trace(err);
    }
  return svn_error_trace(err2);
}
Пример #3
0
svn_error_t *
svn_fs_create(svn_fs_t **fs_p, const char *path, apr_hash_t *fs_config,
              apr_pool_t *pool)
{
  svn_error_t *err;
  svn_error_t *err2;
  fs_library_vtable_t *vtable;

  const char *fs_type = svn_hash__get_cstring(fs_config,
                                              SVN_FS_CONFIG_FS_TYPE,
                                              DEFAULT_FS_TYPE);
  SVN_ERR(get_library_vtable(&vtable, fs_type, pool));

  /* Create the FS directory and write out the fsap-name file. */
  SVN_ERR(svn_io_dir_make_sgid(path, APR_OS_DEFAULT, pool));
  SVN_ERR(write_fs_type(path, fs_type, pool));

  /* Perform the actual creation. */
  *fs_p = fs_new(fs_config, pool);
  SVN_ERR(acquire_fs_mutex());
  err = vtable->create(*fs_p, path, pool, common_pool);
  err2 = release_fs_mutex();
  if (err)
    {
      svn_error_clear(err2);
      return svn_error_trace(err);
    }
  return svn_error_trace(err2);
}
Пример #4
0
svn_error_t *
svn_fs_open(svn_fs_t **fs_p, const char *path, apr_hash_t *fs_config,
            apr_pool_t *pool)
{
  fs_library_vtable_t *vtable;

  SVN_ERR(fs_library_vtable(&vtable, path, pool));
  *fs_p = fs_new(fs_config, pool);
  SVN_MUTEX__WITH_LOCK(common_pool_lock,
                       vtable->open_fs(*fs_p, path, pool, common_pool));
  return SVN_NO_ERROR;
}
Пример #5
0
svn_error_t *
svn_fs_upgrade(const char *path, apr_pool_t *pool)
{
  fs_library_vtable_t *vtable;
  svn_fs_t *fs;

  SVN_ERR(fs_library_vtable(&vtable, path, pool));
  fs = fs_new(NULL, pool);

  SVN_MUTEX__WITH_LOCK(common_pool_lock,
                       vtable->upgrade_fs(fs, path, pool, common_pool));
  return SVN_NO_ERROR;
}
Пример #6
0
/*
 * check_domain_in_region -- (internal) check if region
 * contains persistence_domain file
 */
static int
check_domain_in_region(const char *region_path)
{
	LOG(3, "region_path: %s", region_path);

	struct fs *reg = NULL;
	struct fs_entry *reg_entry;
	char domain_path[PATH_MAX];
	int cpu_cache = 0;

	reg = fs_new(region_path);
	if (reg == NULL) {
		ERR("!fs_new: \"%s\"", region_path);
		cpu_cache = -1;
		goto end;
	}

	while ((reg_entry = fs_read(reg)) != NULL) {
		/*
		 * persistence_domain has to be a file type entry
		 * and it has to be first level child for region;
		 * there is no need to run into deeper levels
		 */
		if (reg_entry->type != FS_ENTRY_FILE ||
				strcmp(reg_entry->name,
				PERSISTENCE_DOMAIN) != 0 ||
				reg_entry->level != 1)
			continue;

		int ret = snprintf(domain_path, PATH_MAX,
			"%s/"PERSISTENCE_DOMAIN,
			region_path);
		if (ret < 0) {
			ERR("snprintf(%p, %d,"
				"%s/"PERSISTENCE_DOMAIN", %s): %d",
				domain_path, PATH_MAX,
				region_path, region_path, ret);
			cpu_cache = -1;
			goto end;
		}
		cpu_cache = check_cpu_cache(domain_path);
	}

end:
	if (reg)
		fs_delete(reg);
	return cpu_cache;
}
Пример #7
0
/*
 * os_auto_flush -- check if platform supports auto flush for all regions
 *
 * Traverse "/sys/bus/nd/devices" path to find all the nvdimm regions,
 * then for each region checks if "persistence_domain" file exists and
 * contains "cpu_cache" string.
 * If for any region "persistence_domain" entry does not exists, or its
 * context is not as expected, assume eADR is not available on this platform.
 */
int
os_auto_flush(void)
{
	LOG(15, NULL);

	char *device_path;
	int cpu_cache = 0;

	device_path = BUS_DEVICE_PATH;

	os_stat_t sdev;
	if (os_stat(device_path, &sdev) != 0 ||
		S_ISDIR(sdev.st_mode) == 0) {
		LOG(3, "eADR not supported");
		return cpu_cache;
	}

	struct fs *dev = fs_new(device_path);
	if (dev == NULL) {
		ERR("!fs_new: \"%s\"", device_path);
		return -1;
	}

	struct fs_entry *dev_entry;

	while ((dev_entry = fs_read(dev)) != NULL) {
		/*
		 * Skip if not a symlink, because we expect that
		 * region on sysfs path is a symlink.
		 * Skip if depth is different than 1, bacause region
		 * we are interested in should be the first level
		 * child for device.
		 */
		if ((dev_entry->type != FS_ENTRY_SYMLINK) ||
				!strstr(dev_entry->name, "region") ||
				dev_entry->level != 1)
			continue;

		LOG(15, "Start traversing region: %s", dev_entry->path);
		cpu_cache = check_domain_in_region(dev_entry->path);
		if (cpu_cache != 1)
			goto end;
	}

end:
	fs_delete(dev);
	return cpu_cache;
}
Пример #8
0
svn_error_t *
svn_fs_recover(const char *path,
               svn_cancel_func_t cancel_func, void *cancel_baton,
               apr_pool_t *pool)
{
  fs_library_vtable_t *vtable;
  svn_fs_t *fs;

  SVN_ERR(fs_library_vtable(&vtable, path, pool));
  fs = fs_new(NULL, pool);

  SVN_MUTEX__WITH_LOCK(common_pool_lock,
                       vtable->open_fs_for_recovery(fs, path, pool,
                                                    common_pool));
  return svn_error_trace(vtable->recover(fs, cancel_func, cancel_baton,
                                         pool));
}
Пример #9
0
svn_error_t *
svn_fs_verify(const char *path,
              svn_cancel_func_t cancel_func,
              void *cancel_baton,
              svn_revnum_t start,
              svn_revnum_t end,
              apr_pool_t *pool)
{
  fs_library_vtable_t *vtable;
  svn_fs_t *fs;

  SVN_ERR(fs_library_vtable(&vtable, path, pool));
  fs = fs_new(NULL, pool);

  SVN_MUTEX__WITH_LOCK(common_pool_lock,
                       vtable->verify_fs(fs, path, cancel_func, cancel_baton,
                                         start, end, pool, common_pool));
  return SVN_NO_ERROR;
}
Пример #10
0
svn_error_t *
svn_fs_pack(const char *path,
            svn_fs_pack_notify_t notify_func,
            void *notify_baton,
            svn_cancel_func_t cancel_func,
            void *cancel_baton,
            apr_pool_t *pool)
{
  fs_library_vtable_t *vtable;
  svn_fs_t *fs;

  SVN_ERR(fs_library_vtable(&vtable, path, pool));
  fs = fs_new(NULL, pool);

  SVN_MUTEX__WITH_LOCK(common_pool_lock,
                       vtable->pack_fs(fs, path, notify_func, notify_baton,
                                       cancel_func, cancel_baton, pool,
                                       common_pool));
  return SVN_NO_ERROR;
}
Пример #11
0
svn_error_t *
svn_fs_upgrade(const char *path, apr_pool_t *pool)
{
  svn_error_t *err;
  svn_error_t *err2;
  fs_library_vtable_t *vtable;
  svn_fs_t *fs;

  SVN_ERR(fs_library_vtable(&vtable, path, pool));
  fs = fs_new(NULL, pool);
  SVN_ERR(acquire_fs_mutex());
  err = vtable->upgrade_fs(fs, path, pool, common_pool);
  err2 = release_fs_mutex();
  if (err)
    {
      svn_error_clear(err2);
      return svn_error_trace(err);
    }
  return svn_error_trace(err2);
}
Пример #12
0
svn_error_t *
svn_fs_open(svn_fs_t **fs_p, const char *path, apr_hash_t *fs_config,
            apr_pool_t *pool)
{
  svn_error_t *err;
  svn_error_t *err2;
  fs_library_vtable_t *vtable;

  SVN_ERR(fs_library_vtable(&vtable, path, pool));
  *fs_p = fs_new(fs_config, pool);
  SVN_ERR(acquire_fs_mutex());
  err = vtable->open_fs(*fs_p, path, pool, common_pool);
  err2 = release_fs_mutex();
  if (err)
    {
      svn_error_clear(err2);
      return svn_error_trace(err);
    }
  return svn_error_trace(err2);
}
Пример #13
0
svn_error_t *
svn_fs_create(svn_fs_t **fs_p, const char *path, apr_hash_t *fs_config,
              apr_pool_t *pool)
{
  fs_library_vtable_t *vtable;

  const char *fs_type = svn_hash__get_cstring(fs_config,
                                              SVN_FS_CONFIG_FS_TYPE,
                                              DEFAULT_FS_TYPE);
  SVN_ERR(get_library_vtable(&vtable, fs_type, pool));

  /* Create the FS directory and write out the fsap-name file. */
  SVN_ERR(svn_io_dir_make_sgid(path, APR_OS_DEFAULT, pool));
  SVN_ERR(write_fs_type(path, fs_type, pool));

  /* Perform the actual creation. */
  *fs_p = fs_new(fs_config, pool);

  SVN_MUTEX__WITH_LOCK(common_pool_lock,
                       vtable->create(*fs_p, path, pool, common_pool));
  return SVN_NO_ERROR;
}
Пример #14
0
svn_error_t *
svn_fs_recover(const char *path,
               svn_cancel_func_t cancel_func, void *cancel_baton,
               apr_pool_t *pool)
{
  svn_error_t *err;
  svn_error_t *err2;
  fs_library_vtable_t *vtable;
  svn_fs_t *fs;

  SVN_ERR(fs_library_vtable(&vtable, path, pool));
  fs = fs_new(NULL, pool);
  SVN_ERR(acquire_fs_mutex());
  err = vtable->open_fs_for_recovery(fs, path, pool, common_pool);
  err2 = release_fs_mutex();
  if (err)
    {
      svn_error_clear(err2);
      return svn_error_trace(err);
    }
  if (! err2)
    err2 = vtable->recover(fs, cancel_func, cancel_baton, pool);
  return svn_error_trace(err2);
}
Пример #15
0
void fs_emu_initialize_textures() {
    if (g_fs_emu_theme.width == 0) {
        fs_emu_fatal("theme is not initialized yet");
    }

    //g_atlas = fs_emu_texture_new_from_file("atlas");
    fs_image *image = fs_image_new();
    image->width = 1024;
    image->height = 1024;
    image->format = FS_IMAGE_FORMAT_RGBA;
    image->data = fs_malloc0(1024 * 1024 * 4);
    initialize_atlas(image);

    g_atlas = fs_new(fs_emu_texture, 1);
    g_atlas->width = image->width;
    g_atlas->height = image->height;
    g_atlas->image = image;
    load_texture(g_atlas);
    fs_emu_set_texture(g_atlas);
    fs_gl_add_context_notification(context_notification_handler, g_atlas);

    if (g_fs_emu_theme.overlay_image[0]) {
        char *path = fs_emu_theme_get_resource(g_fs_emu_theme.overlay_image);
        fs_log("g_fs_emu_theme.overlay_image %s => %s\n",
                g_fs_emu_theme.overlay_image, path);
        if (path) {
            g_fs_emu_overlay_texture = fs_emu_texture_new_from_file(path);
        }
    }

    for (int i = 0; i < FS_EMU_MAX_OVERLAYS; i++) {
        for (int j = 0; j < FS_EMU_MAX_OVERLAY_STATES; j++) {
            fs_emu_texture *tex = NULL;
            char *name = fs_strdup_printf("custom_%d_%d.png",
                    i - FS_EMU_FIRST_CUSTOM_OVERLAY, j);
            char *path = fs_emu_theme_get_resource(name);
            if (!path && g_fs_emu_theme.overlays[i].name) {
                free(name);
                name = fs_strdup_printf("%s_%d.png",
                        g_fs_emu_theme.overlays[i].name, j);
                path = fs_emu_theme_get_resource(name);
            }
            if (path) {
                tex = fs_emu_texture_new_from_file(path);
                g_fs_emu_theme.overlays[i].textures[j] = tex;
                free(path);
            }
            else if (j == 1) {
                char *base_name = fs_strdup_printf("custom_%d.png",
                        i - FS_EMU_FIRST_CUSTOM_OVERLAY);
                path = fs_emu_theme_get_resource(base_name);
                if (!path && g_fs_emu_theme.overlays[i].name) {
                    free(name);
                    name = fs_strdup_printf("%s.png",
                            g_fs_emu_theme.overlays[i].name);
                    path = fs_emu_theme_get_resource(name);
                }
                if (path) {
                    tex = fs_emu_texture_new_from_file(path);
                    g_fs_emu_theme.overlays[i].textures[j] = tex;
                    free(path);
                }
                free(base_name);
            }
            else if (j >= 2) {
                g_fs_emu_theme.overlays[i].textures[j] = \
                        g_fs_emu_theme.overlays[i].textures[j - 1];
            }
            free(name);

            // size will be determined from the last loaded texture/state
            // for the overlay
            if (tex) {
                g_fs_emu_theme.overlays[i].w =
                        (double) tex->width / g_fs_emu_theme.width;
                g_fs_emu_theme.overlays[i].h =
                        (double) tex->height / g_fs_emu_theme.height;
            }
        }
    }
}
Пример #16
0
void fs_test(int tid)
{
  fun_string f[25];
  unsigned char d1[] = "kungfu\0kaleidescopes", d2[] = "funintheSun";
  size_t count;

  printf("[%d] START: FUN STRING test!\n", tid);

  assert(f[1] = fs_new(d1, 20, 0));
  assert(f[2] = fs_new(d1, 20, 0));
  assert(f[3] = fs_new(d2, 11, 0));

  assert(!fs_cmp(f[1], f[2]));
  assert(fs_cmp(f[1], f[3]));

  assert(f[4] = fs_resize(f[1], 10));
  assert(f[5] = fs_resize(f[2], 15));
  assert(f[6] = fs_resize(f[3], 10));
  
  assert(fs_cmp(f[4], f[5]));
  assert(!fs_ncmp(f[4], f[5], 10));
  assert(!fs_ncmp(f[3], f[6], 10));

  assert(f[7] = fs_access(f[1], 3, 10));
  assert(f[8] = fs_access(f[4], 3, 5));
  assert(f[9] = fs_access(f[5], 5, 10));

  assert(!fs_ncmp(f[7], f[8], 3));
  assert(fs_cmp(f[7], f[8]));
  assert(fs_ncmp(f[7], f[9], 5));

  assert(10 == fs_len(f[7]));
  assert(5 == fs_len(f[8]));
  assert(10 == fs_len(f[7]));
  assert(20 == fs_len(f[1]));
  assert(10 == fs_len(f[4]));
  assert(11 == fs_len(f[3]));

  assert(f[10] = fs_set(f[1], '9', 40));
  assert(f[11] = fs_set(f[1], '9', 50));
  assert(f[12] = fs_set(f[1], 'A', 40));

  assert(!fs_ncmp(f[10], f[11], 30));
  assert(fs_cmp(f[10], f[11]));
  assert(fs_cmp(f[10], f[12]));
  assert(fs_cmp(f[1], f[10]));

  assert(f[13] = fs_dup(f[1]));
  assert(f[14] = fs_dup(f[2]));
  assert(f[15] = fs_dup(f[4]));

  assert(!fs_cmp(f[13], f[14]));
  assert(!fs_ncmp(f[13], f[15], 5));
  assert(fs_cmp(f[13], f[6]));

  assert(f[16] = fs_chr(f[1], 'g'));
  assert(f[17] = fs_chr(f[4], 'g'));
  assert(f[18] = fs_rchr(f[1], 'g'));

  assert(!fs_ncmp(f[16], f[17], 3));
  assert(!fs_cmp(f[16], f[18]));
  assert(fs_cmp(f[16], f[7]));

  assert(f[19] = fs_cat(f[3], f[16]));
  assert(f[20] = fs_cat(f[3], f[18]));
  assert(f[21] = fs_ncat(f[3], f[17], 2));

  assert(!fs_cmp(f[19], f[20]));
  assert(fs_cmp(f[19], f[21]));
  assert(!fs_ncmp(f[19], f[21], 13));

  // To test
  // cat
  // ncat

  fs_free(&f[1]);
  fs_free(&f[2]);
  fs_free(&f[3]);
  fs_free(&f[4]);
  fs_free(&f[5]);
  fs_free(&f[6]);
  fs_free(&f[7]);
  fs_free(&f[8]);
  fs_free(&f[9]);
  fs_free(&f[10]);
  fs_free(&f[11]);
  fs_free(&f[12]);
  fs_free(&f[13]);
  fs_free(&f[14]);
  fs_free(&f[15]);
  fs_free(&f[16]);
  fs_free(&f[17]);
  fs_free(&f[18]);
  fs_free(&f[19]);
  fs_free(&f[20]);
  fs_free(&f[21]);

  printf("[%d] Strings destroyed!\n", tid);

  printf("[%d] END: FUN STRING Test!\n\n", tid);
  return;
}
Пример #17
0
fs_emu_texture *fs_emu_texture_new_from_file(const char *name) {
    char *full_name;
    char *path;
    if (fs_path_exists(name)) {
        full_name = fs_strdup(name);
        path = fs_strdup(name);
    }
    else {
        full_name = fs_strconcat(name, ".png", NULL);
        path = fs_get_program_data_file(full_name);
        if (path == NULL) {
            fs_emu_warning("Could not find texture %s\n", full_name);
            return NULL;
        }
    }
    fs_image *image = fs_image_new_from_file(path);
    fs_emu_log("loading texture \"%s\"\n", path);
    free(path);
    if (image == NULL) {
        fs_emu_warning("Could not load texture from %s\n", full_name);
        free(full_name);
        return NULL;
    }
    free(full_name);

    if (fs_emu_get_video_format() == FS_EMU_VIDEO_FORMAT_BGRA) {
        // convert to premultiplied alpha
        if (image->format == FS_IMAGE_FORMAT_RGBA) {
            int num_pixels = image->width * image->height;
            unsigned char *pixels = image->data;
            for (int i = 0; i < num_pixels; i++) {
                unsigned char alpha = pixels[3];
                unsigned char temp = pixels[2];
                pixels[2] = ((int) pixels[0]) * alpha / 255;
                pixels[1] = ((int) pixels[1]) * alpha / 255;
                pixels[0] = ((int) temp) * alpha / 255;
                pixels += 4;
            }
        }
        else {
            // FIXME: should swap R and B here...
        }
    }
    else {
        // convert to premultiplied alpha
        if (image->format == FS_IMAGE_FORMAT_RGBA) {
            int num_pixels = image->width * image->height;
            unsigned char *pixels = image->data;
            for (int i = 0; i < num_pixels; i++) {
                unsigned char alpha = pixels[3];
                // should really divide by 255, but 256 is faster...
                //pixels[0] = ((int) pixels[0]) * alpha / 256;
                //pixels[1] = ((int) pixels[1]) * alpha / 256;
                //pixels[2] = ((int) pixels[2]) * alpha / 256;
                pixels[0] = ((int) pixels[0]) * alpha / 255;
                pixels[1] = ((int) pixels[1]) * alpha / 255;
                pixels[2] = ((int) pixels[2]) * alpha / 255;
                //pixels[0] = (unsigned char) ((pixels[0] * alpha + 0.5) / 255.0);
                //pixels[1] = (unsigned char) ((pixels[1] * alpha + 0.5) / 255.0);
                //pixels[2] = (unsigned char) ((pixels[2] * alpha + 0.5) / 255.0);
                pixels += 4;
            }
        }
    }

    fs_emu_texture *texture = fs_new(fs_emu_texture, 1);
    texture->width = image->width;
    texture->height = image->height;
    texture->image = image;
    load_texture(texture);
    fs_emu_set_texture(texture);

    fs_gl_add_context_notification(context_notification_handler, texture);

    return texture;
}
Пример #18
0
int main(int argc, char **argv) {
    FileSystem *fs;
    FILE* logfile;
    char str[4096];
    //char buffer[4096];
    
    int sd, client, diskserv;
    struct sockaddr_in server_addr, name;
    struct hostent *host;
    
    // connect to disk server
    if ((diskserv = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
		fprintf(stderr, "Socket error\n");
		exit(1);
	}
	
	printf("Trying to connect...\n");
	name.sin_family 	= AF_INET;
	host				= gethostbyname("localhost"); 
	name.sin_port		= htons(atoi(argv[1]));
	memcpy(&name.sin_addr.s_addr, host->h_addr, host->h_length);
	
	if (connect(diskserv, (struct sockaddr *)&name, sizeof(name)) == -1) {
		fprintf(stderr, "Connect error\n");
		exit(1);
	}	
	printf("Connection with the disk is established!\n");	

	// connect to client
    sd = socket(AF_INET, SOCK_STREAM, 0);
    server_addr.sin_family		 = AF_INET;
    server_addr.sin_addr.s_addr  = htonl(INADDR_ANY);
    server_addr.sin_port		 = htons(atoi(argv[2]));
    
    if (bind(sd, (struct sockaddr *) &server_addr, sizeof(server_addr)) == -1) {
    	fprintf(stderr, "Bind error\n");
    	exit(1);
    }
    if (listen(sd, 1) == -1) {
    	fprintf(stderr, "Listen error\n");
    	exit(1);
    }
    fs = fs_new();
    if ((client = accept(sd, 0, 0)) == -1) {
    	fprintf(stderr, "Accept error\n");
    	exit(1);
    }
    logfile = fdopen(client, "w+");
    printf("Connection with client is established!\n");
       
    
    while (1) {
        int result;
        
        recv(client, str, 4096, 0);
        while (isspace(str[strlen(str) - 1])) {
            str[strlen(str) - 1] = 0;
        }
        printf("receive successfully\n");
        result = process_request(str, logfile, fs);
        if (RESULT_EXIT == result) {
            fprintf(logfile, "Goodbye!\n");
            fflush(logfile);
            break;
        } else if (RESULT_DONE == result) {
            fprintf(logfile, "Done\n");
            fflush(logfile);
        } else if (RESULT_YES == result) {
            fprintf(logfile, "Yes\n");
            fflush(logfile);
        } else if (RESULT_NO == result) {
            fprintf(logfile, "No\n");
            fflush(logfile);
        }
        printf("send succussfully.\n");
    }
    close(client);
    close(diskserv);
    close(sd);
    printf("GoodBye!\n");
    fs_free(&fs);
    fclose(logfile);
    return 0;
}
Пример #19
0
svn_fs_t *
svn_fs_new(apr_hash_t *fs_config, apr_pool_t *pool)
{
  return fs_new(fs_config, pool);
}