@@ -75,62 +75,10 @@ impl H2O<Host> {
75
75
return Err ( anyhow:: Error :: msg ( "WATM module version not found" ) ) ;
76
76
}
77
77
78
- Self :: setup_core ( conf, linker, store, module, engine, version)
78
+ Self :: create_core ( conf, linker, store, module, engine, version)
79
79
}
80
80
81
- /// This function is for migrating the v0 core for listener and relay
82
- /// to handle every new connection will create a new separate core (as v0 spec)
83
- pub fn v0_migrate_core ( conf : & WATERConfig , core : & H2O < Host > ) -> Result < Self , anyhow:: Error > {
84
- info ! ( "[HOST] WATERCore H2O v0_migrating..." ) ;
85
-
86
- // reseting the listener accepted_fd or the relay's accepted_fd & dial_fd
87
- // when migrating from existed listener / relay
88
- let version = match & core. version {
89
- Version :: V0 ( v0conf) => {
90
- match v0conf {
91
- Some ( og_v0_conf) => match og_v0_conf. lock ( ) {
92
- Ok ( og_v0_conf) => {
93
- let mut new_v0_conf_inner = og_v0_conf. clone ( ) ;
94
- // reset the new cloned v0conf
95
- new_v0_conf_inner. reset_listener_or_relay ( ) ;
96
-
97
- Version :: V0 ( Some ( Arc :: new ( Mutex :: new ( new_v0_conf_inner) ) ) )
98
- }
99
- Err ( e) => {
100
- return Err ( anyhow:: anyhow!( "Failed to lock v0_conf: {}" , e) ) ?;
101
- }
102
- } ,
103
- None => {
104
- return Err ( anyhow:: anyhow!( "v0_conf is None" ) ) ?;
105
- }
106
- }
107
- }
108
- _ => {
109
- return Err ( anyhow:: anyhow!( "This is not a V0 core" ) ) ?;
110
- }
111
- } ;
112
-
113
- // NOTE: Some of the followings can reuse the existing core, leave to later explore
114
- let wasm_config = wasmtime:: Config :: new ( ) ;
115
-
116
- #[ cfg( feature = "multithread" ) ]
117
- {
118
- wasm_config. wasm_threads ( true ) ;
119
- }
120
-
121
- let engine = Engine :: new ( & wasm_config) ?;
122
- let linker: Linker < Host > = Linker :: new ( & engine) ;
123
-
124
- let module = Module :: from_file ( & engine, & conf. filepath ) ?;
125
-
126
- let host = Host :: default ( ) ;
127
- let store = Store :: new ( & engine, host) ;
128
-
129
- Self :: setup_core ( conf, linker, store, module, engine, Some ( version) )
130
- }
131
-
132
- /// called by init_core() or v0_migrate_core() to setup the core (reduce code duplication)
133
- pub fn setup_core (
81
+ pub fn create_core (
134
82
conf : & WATERConfig ,
135
83
mut linker : Linker < Host > ,
136
84
mut store : Store < Host > ,
@@ -213,6 +161,57 @@ impl H2O<Host> {
213
161
} )
214
162
}
215
163
164
+ // This function is for migrating the v0 core for listener and relay
165
+ // to handle every new connection is creating a new separate core (as v0 spec)
166
+ pub fn v0_migrate_core ( conf : & WATERConfig , core : & H2O < Host > ) -> Result < Self , anyhow:: Error > {
167
+ info ! ( "[HOST] WATERCore H2O v0_migrating..." ) ;
168
+
169
+ // reseting the listener accepted_fd or the relay's accepted_fd & dial_fd
170
+ // when migrating from existed listener / relay
171
+ let version = match & core. version {
172
+ Version :: V0 ( v0conf) => {
173
+ match v0conf {
174
+ Some ( og_v0_conf) => match og_v0_conf. lock ( ) {
175
+ Ok ( og_v0_conf) => {
176
+ let mut new_v0_conf_inner = og_v0_conf. clone ( ) ;
177
+ // reset the new cloned v0conf
178
+ new_v0_conf_inner. reset_listener_or_relay ( ) ;
179
+
180
+ Version :: V0 ( Some ( Arc :: new ( Mutex :: new ( new_v0_conf_inner) ) ) )
181
+ }
182
+ Err ( e) => {
183
+ return Err ( anyhow:: anyhow!( "Failed to lock v0_conf: {}" , e) ) ?;
184
+ }
185
+ } ,
186
+ None => {
187
+ return Err ( anyhow:: anyhow!( "v0_conf is None" ) ) ?;
188
+ }
189
+ }
190
+ }
191
+ _ => {
192
+ return Err ( anyhow:: anyhow!( "This is not a V0 core" ) ) ?;
193
+ }
194
+ } ;
195
+
196
+ // NOTE: Some of the followings can reuse the existing core, leave to later explore
197
+ let wasm_config = wasmtime:: Config :: new ( ) ;
198
+
199
+ #[ cfg( feature = "multithread" ) ]
200
+ {
201
+ wasm_config. wasm_threads ( true ) ;
202
+ }
203
+
204
+ let engine = Engine :: new ( & wasm_config) ?;
205
+ let linker: Linker < Host > = Linker :: new ( & engine) ;
206
+
207
+ let module = Module :: from_file ( & engine, & conf. filepath ) ?;
208
+
209
+ let host = Host :: default ( ) ;
210
+ let store = Store :: new ( & engine, host) ;
211
+
212
+ Self :: create_core ( conf, linker, store, module, engine, Some ( version) )
213
+ }
214
+
216
215
pub fn _prepare ( & mut self , conf : & WATERConfig ) -> Result < ( ) , anyhow:: Error > {
217
216
self . _init ( conf. debug ) ?;
218
217
self . _process_config ( conf) ?; // This is for now needed only by v1_preview
0 commit comments