Xuyi Wang / wolfSSL

Dependents:   OS

Committer:
sPymbed
Date:
Tue Nov 19 14:32:16 2019 +0000
Revision:
16:048e5e270a58
Parent:
15:117db924cf7c
working ssl

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wolfSSL 15:117db924cf7c 1 /* wolfevent.h
wolfSSL 15:117db924cf7c 2 *
wolfSSL 15:117db924cf7c 3 * Copyright (C) 2006-2017 wolfSSL Inc.
wolfSSL 15:117db924cf7c 4 *
wolfSSL 15:117db924cf7c 5 * This file is part of wolfSSL.
wolfSSL 15:117db924cf7c 6 *
wolfSSL 15:117db924cf7c 7 * wolfSSL is free software; you can redistribute it and/or modify
wolfSSL 15:117db924cf7c 8 * it under the terms of the GNU General Public License as published by
wolfSSL 15:117db924cf7c 9 * the Free Software Foundation; either version 2 of the License, or
wolfSSL 15:117db924cf7c 10 * (at your option) any later version.
wolfSSL 15:117db924cf7c 11 *
wolfSSL 15:117db924cf7c 12 * wolfSSL is distributed in the hope that it will be useful,
wolfSSL 15:117db924cf7c 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wolfSSL 15:117db924cf7c 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wolfSSL 15:117db924cf7c 15 * GNU General Public License for more details.
wolfSSL 15:117db924cf7c 16 *
wolfSSL 15:117db924cf7c 17 * You should have received a copy of the GNU General Public License
wolfSSL 15:117db924cf7c 18 * along with this program; if not, write to the Free Software
wolfSSL 15:117db924cf7c 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
wolfSSL 15:117db924cf7c 20 */
wolfSSL 15:117db924cf7c 21
wolfSSL 15:117db924cf7c 22 #ifndef _WOLF_EVENT_H_
wolfSSL 15:117db924cf7c 23 #define _WOLF_EVENT_H_
wolfSSL 15:117db924cf7c 24
wolfSSL 15:117db924cf7c 25 #ifdef __cplusplus
wolfSSL 15:117db924cf7c 26 extern "C" {
wolfSSL 15:117db924cf7c 27 #endif
wolfSSL 15:117db924cf7c 28
wolfSSL 15:117db924cf7c 29 #ifndef SINGLE_THREADED
wolfSSL 15:117db924cf7c 30 #include <wolfssl/wolfcrypt/wc_port.h>
wolfSSL 15:117db924cf7c 31 #endif
wolfSSL 15:117db924cf7c 32
wolfSSL 15:117db924cf7c 33 typedef struct WOLF_EVENT WOLF_EVENT;
wolfSSL 15:117db924cf7c 34 typedef unsigned short WOLF_EVENT_FLAG;
wolfSSL 15:117db924cf7c 35
wolfSSL 15:117db924cf7c 36 typedef enum WOLF_EVENT_TYPE {
wolfSSL 15:117db924cf7c 37 WOLF_EVENT_TYPE_NONE,
wolfSSL 15:117db924cf7c 38 #ifdef WOLFSSL_ASYNC_CRYPT
wolfSSL 15:117db924cf7c 39 WOLF_EVENT_TYPE_ASYNC_WOLFSSL, /* context is WOLFSSL* */
wolfSSL 15:117db924cf7c 40 WOLF_EVENT_TYPE_ASYNC_WOLFCRYPT, /* context is WC_ASYNC_DEV */
wolfSSL 15:117db924cf7c 41 WOLF_EVENT_TYPE_ASYNC_FIRST = WOLF_EVENT_TYPE_ASYNC_WOLFSSL,
wolfSSL 15:117db924cf7c 42 WOLF_EVENT_TYPE_ASYNC_LAST = WOLF_EVENT_TYPE_ASYNC_WOLFCRYPT,
wolfSSL 15:117db924cf7c 43 #endif /* WOLFSSL_ASYNC_CRYPT */
wolfSSL 15:117db924cf7c 44 } WOLF_EVENT_TYPE;
wolfSSL 15:117db924cf7c 45
wolfSSL 15:117db924cf7c 46 typedef enum WOLF_EVENT_STATE {
wolfSSL 15:117db924cf7c 47 WOLF_EVENT_STATE_READY,
wolfSSL 15:117db924cf7c 48 WOLF_EVENT_STATE_PENDING,
wolfSSL 15:117db924cf7c 49 WOLF_EVENT_STATE_DONE,
wolfSSL 15:117db924cf7c 50 } WOLF_EVENT_STATE;
wolfSSL 15:117db924cf7c 51
wolfSSL 15:117db924cf7c 52 struct WOLF_EVENT {
wolfSSL 15:117db924cf7c 53 /* double linked list */
wolfSSL 15:117db924cf7c 54 WOLF_EVENT* next;
wolfSSL 15:117db924cf7c 55 WOLF_EVENT* prev;
wolfSSL 15:117db924cf7c 56
wolfSSL 15:117db924cf7c 57 void* context;
wolfSSL 15:117db924cf7c 58 union {
wolfSSL 15:117db924cf7c 59 void* ptr;
wolfSSL 15:117db924cf7c 60 #ifdef WOLFSSL_ASYNC_CRYPT
wolfSSL 15:117db924cf7c 61 struct WC_ASYNC_DEV* async;
wolfSSL 15:117db924cf7c 62 #endif
wolfSSL 15:117db924cf7c 63 } dev;
wolfSSL 15:117db924cf7c 64 #ifdef HAVE_CAVIUM
wolfSSL 15:117db924cf7c 65 word64 reqId;
wolfSSL 15:117db924cf7c 66 #ifdef WOLFSSL_NITROX_DEBUG
wolfSSL 15:117db924cf7c 67 word32 pendCount;
wolfSSL 15:117db924cf7c 68 #endif
wolfSSL 15:117db924cf7c 69 #endif
wolfSSL 15:117db924cf7c 70 #ifndef WC_NO_ASYNC_THREADING
wolfSSL 15:117db924cf7c 71 pthread_t threadId;
wolfSSL 15:117db924cf7c 72 #endif
wolfSSL 15:117db924cf7c 73 int ret; /* Async return code */
wolfSSL 15:117db924cf7c 74 unsigned int flags;
wolfSSL 15:117db924cf7c 75 WOLF_EVENT_TYPE type;
wolfSSL 15:117db924cf7c 76 WOLF_EVENT_STATE state;
wolfSSL 15:117db924cf7c 77 };
wolfSSL 15:117db924cf7c 78
wolfSSL 15:117db924cf7c 79 enum WOLF_POLL_FLAGS {
wolfSSL 15:117db924cf7c 80 WOLF_POLL_FLAG_CHECK_HW = 0x01,
wolfSSL 15:117db924cf7c 81 };
wolfSSL 15:117db924cf7c 82
wolfSSL 15:117db924cf7c 83 typedef struct {
wolfSSL 15:117db924cf7c 84 WOLF_EVENT* head; /* head of queue */
wolfSSL 15:117db924cf7c 85 WOLF_EVENT* tail; /* tail of queue */
wolfSSL 15:117db924cf7c 86 #ifndef SINGLE_THREADED
wolfSSL 15:117db924cf7c 87 wolfSSL_Mutex lock; /* queue lock */
wolfSSL 15:117db924cf7c 88 #endif
wolfSSL 15:117db924cf7c 89 int count;
wolfSSL 15:117db924cf7c 90 } WOLF_EVENT_QUEUE;
wolfSSL 15:117db924cf7c 91
wolfSSL 15:117db924cf7c 92
wolfSSL 15:117db924cf7c 93 #ifdef HAVE_WOLF_EVENT
wolfSSL 15:117db924cf7c 94
wolfSSL 15:117db924cf7c 95 /* Event */
wolfSSL 15:117db924cf7c 96 WOLFSSL_API int wolfEvent_Init(WOLF_EVENT* event, WOLF_EVENT_TYPE type, void* context);
wolfSSL 15:117db924cf7c 97 WOLFSSL_API int wolfEvent_Poll(WOLF_EVENT* event, WOLF_EVENT_FLAG flags);
wolfSSL 15:117db924cf7c 98
wolfSSL 15:117db924cf7c 99 /* Event Queue */
wolfSSL 15:117db924cf7c 100 WOLFSSL_API int wolfEventQueue_Init(WOLF_EVENT_QUEUE* queue);
wolfSSL 15:117db924cf7c 101 WOLFSSL_API int wolfEventQueue_Push(WOLF_EVENT_QUEUE* queue, WOLF_EVENT* event);
wolfSSL 15:117db924cf7c 102 WOLFSSL_API int wolfEventQueue_Pop(WOLF_EVENT_QUEUE* queue, WOLF_EVENT** event);
wolfSSL 15:117db924cf7c 103 WOLFSSL_API int wolfEventQueue_Poll(WOLF_EVENT_QUEUE* queue, void* context_filter,
wolfSSL 15:117db924cf7c 104 WOLF_EVENT** events, int maxEvents, WOLF_EVENT_FLAG flags, int* eventCount);
wolfSSL 15:117db924cf7c 105 WOLFSSL_API int wolfEventQueue_Count(WOLF_EVENT_QUEUE* queue);
wolfSSL 15:117db924cf7c 106 WOLFSSL_API void wolfEventQueue_Free(WOLF_EVENT_QUEUE* queue);
wolfSSL 15:117db924cf7c 107
wolfSSL 15:117db924cf7c 108 /* the queue mutex must be locked prior to calling these */
wolfSSL 15:117db924cf7c 109 WOLFSSL_API int wolfEventQueue_Add(WOLF_EVENT_QUEUE* queue, WOLF_EVENT* event);
wolfSSL 15:117db924cf7c 110 WOLFSSL_API int wolfEventQueue_Remove(WOLF_EVENT_QUEUE* queue, WOLF_EVENT* event);
wolfSSL 15:117db924cf7c 111
wolfSSL 15:117db924cf7c 112
wolfSSL 15:117db924cf7c 113 #endif /* HAVE_WOLF_EVENT */
wolfSSL 15:117db924cf7c 114
wolfSSL 15:117db924cf7c 115
wolfSSL 15:117db924cf7c 116 #ifdef __cplusplus
wolfSSL 15:117db924cf7c 117 } /* extern "C" */
wolfSSL 15:117db924cf7c 118 #endif
wolfSSL 15:117db924cf7c 119
wolfSSL 15:117db924cf7c 120 #endif /* _WOLF_EVENT_H_ */
wolfSSL 15:117db924cf7c 121