kinetic-c  v0.12.0
Seagate Kinetic Protocol Client Library for C
blocking_flush.c
Go to the documentation of this file.
1 /*
2 * kinetic-c
3 * Copyright (C) 2015 Seagate Technology.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20 
21 #include "kinetic_client.h"
22 #include "kinetic_types.h"
23 #include "byte_array.h"
24 #include <stdlib.h>
25 #include <getopt.h>
26 #include <stdio.h>
27 #include <sys/param.h>
28 #include <sys/stat.h>
29 #include <sys/file.h>
30 #include <ctype.h>
31 
32 #include <openssl/sha.h>
33 
34 static void do_flush(KineticSession *session) {
35  /* Send a Flush command.
36  * Blocking, because the completion closure is NULL. */
37  KineticStatus status = KineticClient_Flush(session, NULL);
38  printf("Flush status: %s\n", Kinetic_GetStatusDescription(status));
39 
40  /* No cleanup necessary */
41 }
42 
43 int main(int argc, char** argv)
44 {
45  (void)argc;
46  (void)argv;
47 
48  // Initialize kinetic-c and configure sessions
49  KineticSession* session;
50  KineticClientConfig clientConfig = {
51  .logFile = "stdout",
52  .logLevel = 1,
53  };
54  KineticClient * client = KineticClient_Init(&clientConfig);
55  if (client == NULL) { return 1; }
56  const char HmacKeyString[] = "asdfasdf";
57  KineticSessionConfig sessionConfig = {
58  .host = "localhost",
59  .port = KINETIC_PORT,
60  .clusterVersion = 0,
61  .identity = 1,
62  .hmacKey = ByteArray_CreateWithCString(HmacKeyString),
63  };
64  KineticStatus status = KineticClient_CreateSession(&sessionConfig, client, &session);
65  if (status != KINETIC_STATUS_SUCCESS) {
66  fprintf(stderr, "Failed connecting to the Kinetic device w/status: %s\n",
68  exit(1);
69  }
70 
71  do_flush(session);
72 
73  // Shutdown client connection and cleanup
75  KineticClient_Shutdown(client);
76  return 0;
77 }
Operation successful.
KineticStatus KineticClient_CreateSession(KineticSessionConfig *const config, KineticClient *const client, KineticSession **session)
Creates a session with the Kinetic Device per specified configuration.
KineticStatus KineticClient_Flush(KineticSession *const session, KineticCompletionClosure *closure)
Executes a FLUSHALLDATA operation to flush pending PUTs or DELETEs.
Structure used to specify the configuration for a session.
static void do_flush(KineticSession *session)
KineticStatus KineticClient_DestroySession(KineticSession *const session)
Closes the connection to a host.
char host[256]
Host name/IP address of Kinetic Device.
const char * Kinetic_GetStatusDescription(KineticStatus status)
Provides a string representation for a KineticStatus code.
Definition: kinetic_types.c:67
#define KINETIC_PORT
Default kinetic port.
Definition: kinetic_types.h:40
const char * logFile
Path to log file. Specify 'stdout' to log to STDOUT or NULL to disable logging.
int main(int argc, char **argv)
KineticStatus
Kinetic status codes.
Configuration values for the KineticClient connection.
void KineticClient_Shutdown(KineticClient *const client)
Performs shutdown/cleanup of the kinetic-c client library.
KineticClient * KineticClient_Init(KineticClientConfig *config)
Initializes the Kinetic API and configures logging.
ByteArray ByteArray_CreateWithCString(const char *str)
Definition: byte_array.c:38