@@ -641,9 +641,8 @@ open(Host, Options) ->
641
641
% %------------------------------------------------------------------------------
642
642
-spec close (eipmi :session ()) -> ok | {error , term ()}.
643
643
close (Session ) ->
644
- Result = supervisor :terminate_child (? MODULE , Session ),
645
- supervisor :delete_child (? MODULE , Session ),
646
- Result .
644
+ ets :delete (eipmi_sessions , Session ),
645
+ supervisor :terminate_child (? MODULE , Session ).
647
646
648
647
% %------------------------------------------------------------------------------
649
648
% % @doc
@@ -1144,8 +1143,14 @@ poll_sel(Session) ->
1144
1143
- spec poll_sel (session (), non_neg_integer (), boolean ()) ->
1145
1144
{ok , pid ()} | {error , term ()}.
1146
1145
poll_sel (Session = {session , _ , _ }, Interval , Clear ) when Interval > 0 ->
1147
- Children = supervisor :which_children (? MODULE ),
1148
- poll_sel (get_session (Session , Children ), Session , Interval , Clear ).
1146
+ Result =
1147
+ case ets :lookup (eipmi_sessions , Session ) of
1148
+ [{_ , Pid , _ }] ->
1149
+ {ok , Pid };
1150
+ [] ->
1151
+ {error , no_session }
1152
+ end ,
1153
+ poll_sel (Result , Session , Interval , Clear ).
1149
1154
poll_sel ({ok , Pid }, Session , Interval , Clear ) ->
1150
1155
start_poll (Pid , Session , [{read_sel , Interval }, {clear_sel , Clear }]);
1151
1156
poll_sel (Error , _Session , _Interval , _Clear ) ->
@@ -1506,8 +1511,13 @@ id_to_fru(FruId, SdrRepository) ->
1506
1511
% %------------------------------------------------------------------------------
1507
1512
- spec sessions () -> [session ()].
1508
1513
sessions () ->
1509
- Cs = supervisor :which_children (? MODULE ),
1510
- [S || {S = {session , _ , _ }, P , _ , _ } <- Cs , is_pid (P )].
1514
+ ets :select (eipmi_sessions , [
1515
+ {
1516
+ {'$1' , '$2' },
1517
+ [{'=:=' , session , {element , '$1' , 1 }}, {is_pid , '$2' }],
1518
+ ['$1' ]
1519
+ }
1520
+ ]).
1511
1521
1512
1522
% %------------------------------------------------------------------------------
1513
1523
% % @doc
@@ -1544,6 +1554,12 @@ stop(_State) -> ok.
1544
1554
% % @private
1545
1555
% %------------------------------------------------------------------------------
1546
1556
init ([]) ->
1557
+ ets :new (eipmi_sessions , [
1558
+ named_table ,
1559
+ public ,
1560
+ {write_concurrency , auto },
1561
+ {read_concurrency , true }
1562
+ ]),
1547
1563
TrapPorts = application :get_env (? MODULE , trap_ports , []),
1548
1564
{ok , {{one_for_one , 5 , 1000 }, [trap_spec (Port ) || Port <- TrapPorts ]}}.
1549
1565
@@ -1565,12 +1581,7 @@ start_session(Target, Options) ->
1565
1581
Session = {session , Target , {self (), make_ref ()}},
1566
1582
Start = {eipmi_session , start_link , [Session , Options ]},
1567
1583
Spec = {Session , Start , temporary , 2000 , worker , [eipmi_session ]},
1568
- case supervisor :start_child (? MODULE , Spec ) of
1569
- Error = {error , _ } ->
1570
- Error ;
1571
- Ok when element (1 , Ok ) =:= ok ->
1572
- {ok , Session }
1573
- end .
1584
+ start_session (Spec ).
1574
1585
1575
1586
% %------------------------------------------------------------------------------
1576
1587
% % @private
@@ -1579,24 +1590,36 @@ start_poll(SessionPid, Session = {session, _, _}, Options) ->
1579
1590
Id = {poll , erlang :make_ref ()},
1580
1591
Start = {eipmi_poll , start_link , [SessionPid , Session , Options ]},
1581
1592
Spec = {Id , Start , temporary , brutal_kill , worker , [eipmi_poll ]},
1582
- supervisor :start_child (? MODULE , Spec ).
1593
+ start_session (Spec ).
1594
+
1595
+ % %------------------------------------------------------------------------------
1596
+ % % @private
1597
+ % %------------------------------------------------------------------------------
1598
+ start_session (Spec = {Id , _ , _ , _ , _ , _ }) ->
1599
+ case supervisor :start_child (? MODULE , Spec ) of
1600
+ Error = {error , _ } ->
1601
+ Error ;
1602
+ {ok , Pid } ->
1603
+ ets :insert (eipmi_sessions , {Id , Pid }),
1604
+ {ok , Id }
1605
+ end .
1583
1606
1584
1607
% %------------------------------------------------------------------------------
1585
1608
% % @private
1586
1609
% %------------------------------------------------------------------------------
1587
1610
with_session (Session , Fun ) ->
1588
- Children = supervisor :which_children (? MODULE ),
1589
- with_session_ (get_session (Session , Children ), Fun ).
1611
+ with_session_ (get_session (Session ), Fun ).
1590
1612
with_session_ ({ok , Pid }, Fun ) -> ? EIPMI_CATCH (Fun (Pid ));
1591
1613
with_session_ (Error , _Fun ) -> Error .
1592
1614
1593
1615
% %------------------------------------------------------------------------------
1594
1616
% % @private
1595
1617
% %------------------------------------------------------------------------------
1596
- get_session (S , Cs ) ->
1597
- get_session ([P || {Id , P , _ , _ } <- Cs , Id =:= S andalso is_pid (P )]).
1598
- get_session ([]) -> {error , no_session };
1599
- get_session ([P ]) -> {ok , P }.
1618
+ get_session (S ) ->
1619
+ case ets :lookup (eipmi_sessions , S ) of
1620
+ [] -> {error , no_session };
1621
+ [{_ , Pid }] -> {ok , Pid }
1622
+ end .
1600
1623
1601
1624
% %------------------------------------------------------------------------------
1602
1625
% % @private
0 commit comments