winverbs: map WSA error codes to winverbs status values
[mirror/winof/.git] / core / winverbs / user / wv_main.cpp
1 /*\r
2  * Copyright (c) 2008 Intel Corporation. All rights reserved.\r
3  *\r
4  * This software is available to you under the OpenIB.org BSD license\r
5  * below:\r
6  *\r
7  *     Redistribution and use in source and binary forms, with or\r
8  *     without modification, are permitted provided that the following\r
9  *     conditions are met:\r
10  *\r
11  *      - Redistributions of source code must retain the above\r
12  *        copyright notice, this list of conditions and the following\r
13  *        disclaimer.\r
14  *\r
15  *      - Redistributions in binary form must reproduce the above\r
16  *        copyright notice, this list of conditions and the following\r
17  *        disclaimer in the documentation and/or other materials\r
18  *        provided with the distribution.\r
19  *\r
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AWV\r
23  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
24  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
25  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
26  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
27  * SOFTWARE.\r
28  */\r
29 \r
30 #include "wv_memory.h"\r
31 #include "wv_provider.h"\r
32 #include "wv_base.h"\r
33 \r
34 volatile LONG WvRef;\r
35 HANDLE heap;\r
36 \r
37 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)\r
38 {\r
39         UNREFERENCED_PARAMETER(hInstance);\r
40         UNREFERENCED_PARAMETER(lpReserved);\r
41 \r
42         switch (dwReason) {\r
43         case DLL_PROCESS_ATTACH:\r
44                 heap = HeapCreate(0, 0, 0);\r
45                 if (heap == NULL) {\r
46                         return FALSE;\r
47                 }\r
48                 break;\r
49         case DLL_PROCESS_DETACH:\r
50                 HeapDestroy(heap);\r
51                 break;\r
52         default:\r
53                 break;\r
54         }\r
55 \r
56         return TRUE;\r
57 }\r
58 \r
59 STDAPI DllCanUnloadNow(void)\r
60 {\r
61         return WvRef ? S_FALSE : S_OK;\r
62 }\r
63 \r
64 __declspec(dllexport) HRESULT WvGetObject(REFIID riid, LPVOID FAR* ppvObj)\r
65 {\r
66         if (riid != IID_IWVProvider) {\r
67                 *ppvObj = NULL;\r
68                 return E_NOINTERFACE;\r
69         }\r
70 \r
71         return CWVProvider::CreateInstance((IWVProvider **) ppvObj);\r
72 }\r
73 \r
74 HRESULT WvConvertIbStatus(ib_api_status_t status)\r
75 {\r
76         switch (status) {\r
77         case IB_SUCCESS:                                return WV_SUCCESS;\r
78         case IB_INSUFFICIENT_RESOURCES: return WV_INSUFFICIENT_RESOURCES;\r
79         case IB_INSUFFICIENT_MEMORY:    return WV_NO_MEMORY;\r
80         case IB_INVALID_PARAMETER:              return WV_INVALID_PARAMETER;\r
81         case IB_INVALID_SETTING:                return WV_INVALID_PARAMETER;\r
82         case IB_NOT_FOUND:                              return WV_INVALID_ADDRESS;\r
83         case IB_TIMEOUT:                                return WV_TIMEOUT;\r
84         case IB_CANCELED:                               return WV_CANCELLED;\r
85         case IB_INTERRUPTED:                    return WV_CANCELLED;\r
86         case IB_INVALID_PERMISSION:             return WV_ACCESS_VIOLATION;\r
87         case IB_UNSUPPORTED:                    return WV_NOT_SUPPORTED;\r
88         case IB_OVERFLOW:                               return WV_BUFFER_OVERFLOW;\r
89         case IB_MAX_MCAST_QPS_REACHED:  return WV_INSUFFICIENT_RESOURCES;\r
90         case IB_INVALID_QP_STATE:               return WV_INVALID_PARAMETER;\r
91         case IB_INVALID_APM_STATE:              return WV_INVALID_PARAMETER;\r
92         case IB_INVALID_PORT_STATE:             return WV_INVALID_PARAMETER;\r
93         case IB_INVALID_STATE:                  return WV_INVALID_PARAMETER;\r
94         case IB_RESOURCE_BUSY:                  return WV_DEVICE_BUSY;\r
95         case IB_INVALID_PKEY:                   return WV_INVALID_HANDLE;\r
96         case IB_INVALID_LKEY:                   return WV_INVALID_HANDLE;\r
97         case IB_INVALID_RKEY:                   return WV_INVALID_HANDLE;\r
98         case IB_INVALID_MAX_WRS:                return WV_INSUFFICIENT_RESOURCES;\r
99         case IB_INVALID_MAX_SGE:                return WV_INSUFFICIENT_RESOURCES;\r
100         case IB_INVALID_CQ_SIZE:                return WV_INSUFFICIENT_RESOURCES;\r
101         case IB_INVALID_SRQ_SIZE:               return WV_INSUFFICIENT_RESOURCES;\r
102         case IB_INVALID_SERVICE_TYPE:   return WV_NOT_SUPPORTED;\r
103         case IB_INVALID_GID:                    return WV_INVALID_ADDRESS;\r
104         case IB_INVALID_LID:                    return WV_INVALID_ADDRESS;\r
105         case IB_INVALID_GUID:                   return WV_INVALID_ADDRESS;\r
106         case IB_INVALID_GUID_MASK:              return WV_INVALID_ADDRESS;\r
107         case IB_INVALID_CA_HANDLE:              return WV_INVALID_HANDLE;\r
108         case IB_INVALID_AV_HANDLE:              return WV_INVALID_HANDLE;\r
109         case IB_INVALID_CQ_HANDLE:              return WV_INVALID_HANDLE;\r
110         case IB_INVALID_QP_HANDLE:              return WV_INVALID_HANDLE;\r
111         case IB_INVALID_SRQ_HANDLE:             return WV_INVALID_HANDLE;\r
112         case IB_INVALID_PD_HANDLE:              return WV_INVALID_HANDLE;\r
113         case IB_INVALID_MR_HANDLE:              return WV_INVALID_HANDLE;\r
114         case IB_INVALID_FMR_HANDLE:             return WV_INVALID_HANDLE;\r
115         case IB_INVALID_MW_HANDLE:              return WV_INVALID_HANDLE;\r
116         case IB_INVALID_MCAST_HANDLE:   return WV_INVALID_HANDLE;\r
117         case IB_INVALID_CALLBACK:               return WV_INVALID_PARAMETER;\r
118         case IB_INVALID_AL_HANDLE:              return WV_INVALID_HANDLE;\r
119         case IB_INVALID_HANDLE:                 return WV_INVALID_HANDLE;\r
120         case IB_ERROR:                                  return WV_UNKNOWN_ERROR;\r
121         case IB_REMOTE_ERROR:                   return WV_REMOTE_OP_ERROR;\r
122         case IB_VERBS_PROCESSING_DONE:  return WV_SUCCESS;\r
123         case IB_INVALID_WR_TYPE:                return WV_INVALID_PARAMETER;\r
124         case IB_QP_IN_TIMEWAIT:                 return WV_INVALID_PARAMETER;\r
125         case IB_EE_IN_TIMEWAIT:                 return WV_INVALID_PARAMETER;\r
126         case IB_INVALID_PORT:                   return WV_INVALID_ADDRESS;\r
127         case IB_NOT_DONE:                               return WV_PENDING;\r
128         case IB_INVALID_INDEX:                  return WV_INVALID_PARAMETER;\r
129         case IB_NO_MATCH:                               return WV_INVALID_PARAMETER;\r
130         case IB_PENDING:                                return WV_PENDING;\r
131         default:                                                return WV_UNKNOWN_ERROR;\r
132         }\r
133 }\r
134 \r
135 HRESULT WvConvertWSAStatus(int status)\r
136 {\r
137         switch (status) {\r
138         case 0:                                                 return WV_SUCCESS;\r
139         case WSAEADDRINUSE:                             return WV_ADDRESS_ALREADY_EXISTS;\r
140         case WSAEADDRNOTAVAIL:                  return WV_INVALID_ADDRESS;\r
141         case WSAENETDOWN:                               return WV_HOST_UNREACHABLE;\r
142         case WSAENETUNREACH:                    return WV_HOST_UNREACHABLE;\r
143         case WSAECONNABORTED:                   return WV_CONNECTION_ABORTED;\r
144         case WSAEISCONN:                                return WV_CONNECTION_ACTIVE;\r
145         case WSAENOTCONN:                               return WV_CONNECTION_INVALID;\r
146         case WSAETIMEDOUT:                              return WV_IO_TIMEOUT;\r
147         case WSAECONNREFUSED:                   return WV_CONNECTION_REFUSED;\r
148         case WSAEHOSTUNREACH:                   return WV_HOST_UNREACHABLE;\r
149         case WSAEACCES:                                 return WV_ADDRESS_ALREADY_EXISTS;\r
150         default:                                                return WV_UNKNOWN_ERROR;\r
151         }\r
152 }