diff options
| -rw-r--r-- | src/kiro-client.c | 32 | ||||
| -rw-r--r-- | src/kiro-client.h | 33 | 
2 files changed, 58 insertions, 7 deletions
diff --git a/src/kiro-client.c b/src/kiro-client.c index 92fd6b1..b9c33c5 100644 --- a/src/kiro-client.c +++ b/src/kiro-client.c @@ -424,7 +424,7 @@ fail:  int -kiro_client_sync (KiroClient *self) +kiro_client_sync_partial (KiroClient *self, gulong remote_offset, gulong size, gulong local_offset)  {      g_return_val_if_fail (self != NULL, -1);      KiroClientPrivate *priv = KIRO_CLIENT_GET_PRIVATE (self); @@ -436,8 +436,29 @@ kiro_client_sync (KiroClient *self)      struct kiro_connection_context *ctx = (struct kiro_connection_context *)priv->conn->context; +    if (remote_offset > ctx->peer_mr.length) { +        g_warning ("kiro_client_sync_partial: remote_offset too large! Won't sync."); +        return -1; +    } + +    gulong read_size = ctx->peer_mr.length; +    if (size > 0) +        read_size = size; +    else if (remote_offset > 0) +        read_size -= remote_offset;  //read to the end of the memory, starting at offset + +    if ((remote_offset + read_size) > ctx->peer_mr.length) { +        g_warning ("kiro_client_sync_partial: remote_offset + read_size would exceed remote memory boundary! Won't sync."); +        return -1; +    } + +    if ((local_offset + read_size) > ctx->rdma_mr->size) { +        g_warning ("kiro_client_sync_partial: local_offset + read_size would exceed local memory boundary! Won't sync."); +        return -1; +    } +      G_LOCK (sync_lock); -    if (rdma_post_read (priv->conn, priv->conn, ctx->rdma_mr->mem, ctx->peer_mr.length, ctx->rdma_mr->mr, 0, (uint64_t)ctx->peer_mr.addr, ctx->peer_mr.rkey)) { +    if (rdma_post_read (priv->conn, priv->conn, ctx->rdma_mr->mem + local_offset, read_size, ctx->rdma_mr->mr, 0, (uint64_t)ctx->peer_mr.addr + remote_offset, ctx->peer_mr.rkey)) {          g_critical ("Failed to RDMA_READ from server: %s", strerror (errno));          goto fail;      } @@ -470,6 +491,13 @@ fail:  } +int +kiro_client_sync (KiroClient *self) +{ +    return kiro_client_sync_partial (self, 0, 0, 0); +} + +  gboolean  ping_timeout (gpointer data) { diff --git a/src/kiro-client.h b/src/kiro-client.h index 3be2621..1941c7a 100644 --- a/src/kiro-client.h +++ b/src/kiro-client.h @@ -97,7 +97,7 @@ KiroClient* kiro_client_new                 (void);   *   automatically freed when calling this function. If you want to continue   *   using the memory after freeing the #KiroClient, make sure to memcpy() it   *   first, using the informations obtained from kiro_client_get_memory() and - *   kiro_client_get_memory_size().  + *   kiro_client_get_memory_size().   * See also:   *   kiro_client_new, kiro_client_connect   */ @@ -118,7 +118,7 @@ void        kiro_client_free                (KiroClient *client);   *   @dest_port.   * Note:   *   When building a connection to the server, memory for the transmission is - *   created as well.  + *   created as well.   * See also:   *   kiro_server_new   */ @@ -152,14 +152,37 @@ void        kiro_client_disconnect             (KiroClient *client);   *   using kiro_client_get_memory().   * Note:   *   The server can send a 'reallocation' request to the client, forcing it to - *   reallocate new memory with the next occurrence of kiro_client_sync(), - *   freeing the old memory in the process. + *   reallocate new memory freeing the old memory in the process. This might + *   change remote and local memory layout at any time!   *See also: - *    kiro_client_get_memory, kiro_cient_connect + *    kiro_client_sync_partial, kiro_client_get_memory, kiro_cient_connect   */  int         kiro_client_sync                (KiroClient *client);  /** + * kiro_client_sync_partial - Read data from the connected server + * @client: (transfer none): The #KiroServer to use sync on + * @remote_offset: remote read offset in bytes + * @size: ammount of bytes to read. 0 for 'until end' + * @local_offset: offset for the storage in the local buffer + * Returns: + *   0 if successful, -1 in case of synchronisation error + * Description: + *   This synchronizes the client with the server, clining the memory + *   provided by the server to the local client. The memory can be accessed by + *   using kiro_client_get_memory(). Uses the offset parameters to determine + *   which memory region to read from the server and where to store the + *   information to. + * Note: + *   The server can send a 'reallocation' request to the client, forcing it to + *   reallocate new memory freeing the old memory in the process. This might + *   change remote and local memory layout at any time! + *See also: + *    kiro_client_sync, kiro_client_get_memory, kiro_cient_connect + */ +int         kiro_client_sync_partial        (KiroClient *client, gulong remote_offset, gulong size, gulong local_offset); + +/**   * kiro_client_ping_server - Sends a PING to the server   * @client: (transfer none): The #KiroServer to send the PING from   * Returns:  | 
