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