| 1 | /* |
|---|
| 2 | * mycached - memcached protocol handler for mysqld |
|---|
| 3 | * |
|---|
| 4 | * Copyright (C) 2009 Cybozu Labs, Inc. |
|---|
| 5 | * |
|---|
| 6 | * This program is free software; you can redistribute it and/or modify it under |
|---|
| 7 | * the terms of the GNU General Public License as published by the FreeSoftware |
|---|
| 8 | * Foundation; either version 2 of the License. |
|---|
| 9 | * |
|---|
| 10 | * This program is distributed in the hope that it will be useful, but WITHOUT |
|---|
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|---|
| 12 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|---|
| 13 | * details. |
|---|
| 14 | * |
|---|
| 15 | * You should have received a copy of the GNU General Public License along with |
|---|
| 16 | * this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
|---|
| 17 | * Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 18 | */ |
|---|
| 19 | |
|---|
| 20 | #include "mycached.hh" |
|---|
| 21 | #include "mycached.cc" |
|---|
| 22 | extern "C" { |
|---|
| 23 | #ifdef MYCACHED_USE_SELECT |
|---|
| 24 | # include "picoev_select.c" |
|---|
| 25 | #elif defined(MYCACHED_USE_KQUEUE) |
|---|
| 26 | # include "picoev_kqueue.c" |
|---|
| 27 | #elif defined(MYCACHED_USE_EPOLL) |
|---|
| 28 | # include "picoev_epoll.c" |
|---|
| 29 | #else |
|---|
| 30 | # error "define one of: MYCACHED_USE_SELECT, MYCACHED_USE_KQUEUE, MYCACHED_USE_EPOLL" |
|---|
| 31 | #endif |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | #define SETUP_ARG(i, t, n) \ |
|---|
| 35 | do { \ |
|---|
| 36 | args->arg_type[i] = t; \ |
|---|
| 37 | args->maybe_null[i] = n; \ |
|---|
| 38 | } while (0) |
|---|
| 39 | #define SETUP_ARG_IF(i, t, n) \ |
|---|
| 40 | do { \ |
|---|
| 41 | if (i < args->arg_count) \ |
|---|
| 42 | SETUP_ARG(i, t, n); \ |
|---|
| 43 | } while (0) |
|---|
| 44 | |
|---|
| 45 | extern "C" |
|---|
| 46 | my_bool |
|---|
| 47 | mycached_start_init(UDF_INIT* initid, UDF_ARGS* args, char* message) |
|---|
| 48 | { |
|---|
| 49 | if (args->arg_count != 2) { |
|---|
| 50 | strcpy(message, "mycached_start(host,port): invalid arguments"); |
|---|
| 51 | return 1; |
|---|
| 52 | } |
|---|
| 53 | initid->maybe_null = 0; |
|---|
| 54 | SETUP_ARG(0, INT_RESULT, 0); |
|---|
| 55 | SETUP_ARG(1, INT_RESULT, 0); |
|---|
| 56 | return 0; |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | extern "C" |
|---|
| 60 | void |
|---|
| 61 | mycached_start_deinit(UDF_INIT* initid) |
|---|
| 62 | { |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | extern "C" |
|---|
| 66 | long long |
|---|
| 67 | mycached_start(UDF_INIT* initid, UDF_ARGS* args, char* is_null, char* error) |
|---|
| 68 | { |
|---|
| 69 | return mycached::conn_t::start_server(*(long long*)args->args[0], |
|---|
| 70 | *(long long*)args->args[1]); |
|---|
| 71 | } |
|---|