     GenServer.cast(esme, {:reply, pdu, reply_pdu})
   end
 
+  def stop(esme) do
+    GenServer.cast(esme, :stop)
+  end
+
   def handle_pdu(esme, pdu) do
     GenServer.call(esme, {:handle_pdu, pdu})
   end

    do_handle_send_pdu_result(pdu, send_pdu_result, st)
  end

  def handle_cast({:send_pdu, pdu}, st) do
    new_st = do_send_pdu(pdu, st)
    {:noreply, new_st}

    {:noreply, new_st}
  end

  def handle_cast(:stop, st) do
    Session.stop(st.session)
    {:noreply, st}
  end

  def handle_cast({:cast, request}, st) do
    new_module_state = st.module.handle_cast(request, st.module_state)
    new_st = %ESME{ st | module_state: new_module_state }
    {:noreply, new_st}
  end

  def handle_info({:tick, time}, st) do
    do_handle_tick(time, st)
  end

  def handle_info({:info, request}, st) do
    new_module_state = st.module.handle_info(request, st.module_state)
    new_st = %ESME{ st | module_state: new_module_state }
    {:noreply, new_st}
  end

  # Private functions
