Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00014 #include <stdio.h>
00015 #include <stdlib.h>
00016 #include <string.h>
00017 #include <unistd.h>
00018
00019 #include <libgearman/gearman.h>
00020
00021 static void usage(char *name);
00022
00023 int main(int argc, char *argv[])
00024 {
00025 int c;
00026 char *host= NULL;
00027 in_port_t port= 0;
00028 gearman_return_t ret;
00029 gearman_client_st client;
00030
00031 while ((c = getopt(argc, argv, "h:p:")) != -1)
00032 {
00033 switch(c)
00034 {
00035 case 'h':
00036 host= optarg;
00037 break;
00038
00039 case 'p':
00040 port= (in_port_t)atoi(optarg);
00041 break;
00042
00043 default:
00044 usage(argv[0]);
00045 exit(1);
00046 }
00047 }
00048
00049 if (argc != (optind + 1))
00050 {
00051 usage(argv[0]);
00052 exit(1);
00053 }
00054
00055 if (gearman_client_create(&client) == NULL)
00056 {
00057 fprintf(stderr, "Memory allocation failure on client creation\n");
00058 exit(1);
00059 }
00060
00061 ret= gearman_client_add_server(&client, host, port);
00062 if (ret != GEARMAN_SUCCESS)
00063 {
00064 fprintf(stderr, "%s\n", gearman_client_error(&client));
00065 exit(1);
00066 }
00067
00068 ret= gearman_client_echo(&client, (void *)argv[optind],
00069 (size_t)strlen(argv[optind]));
00070 if (ret != GEARMAN_SUCCESS)
00071 fprintf(stderr, "%s\n", gearman_client_error(&client));
00072
00073 gearman_client_free(&client);
00074
00075 return 0;
00076 }
00077
00078 static void usage(char *name)
00079 {
00080 printf("\nusage: %s [-h <host>] [-p <port>] <string>\n", name);
00081 printf("\t-h <host> - job server host\n");
00082 printf("\t-p <port> - job server port\n");
00083 }