Skip to content

Commit

Permalink
fix http and socket if defaulttimeoutSeconds<0 (#237)
Browse files Browse the repository at this point in the history
* fix http and socket if defaulttimeoutSeconds<0'

* [skip ci] modify timeout >= 0 to > 0 in socket

* [skip ci] fix rtsp example
  • Loading branch information
rhoninl authored Sep 2, 2022
1 parent 4c6d9b6 commit be4bd7f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ data:
driverSku: HikVision
driverImage: edgenesis/camera-python:v0.0.1
instructions: |
instructions:
instructionSettings:
defaultTimeoutSeconds: 0
instructions:
capture:
info:
stream:
Expand Down
9 changes: 6 additions & 3 deletions pkg/deviceshifu/deviceshifuHTTP/deviceshifuHTTP.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ import (
"context"
"errors"
"fmt"
"github.com/edgenesis/shifu/pkg/deviceshifu/deviceshifubase"
"github.com/edgenesis/shifu/pkg/k8s/api/v1alpha1"
"io"
"log"
"net/http"
"strconv"
"strings"
"time"

"github.com/edgenesis/shifu/pkg/deviceshifu/deviceshifubase"
"github.com/edgenesis/shifu/pkg/k8s/api/v1alpha1"

"k8s.io/client-go/rest"
)

Expand Down Expand Up @@ -202,7 +203,9 @@ func (handler DeviceCommandHandlerHTTP) commandHandleFunc() http.HandlerFunc {

fallthrough
case http.MethodGet:
if timeout == 0 {
// for shifu.cloud timeout=0 is emptyomit
// for hikivison's rtsp stream need never timeout
if timeout <= 0 {
ctx, cancel = context.WithCancel(context.Background())
} else {
ctx, cancel = context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second)
Expand Down
7 changes: 4 additions & 3 deletions pkg/deviceshifu/deviceshifuSocket/deviceshifuSocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"bufio"
"encoding/json"
"fmt"
"github.com/edgenesis/shifu/pkg/deviceshifu/deviceshifubase"
"github.com/edgenesis/shifu/pkg/k8s/api/v1alpha1"
"log"
"net"
"net/http"
"strings"
"time"

"github.com/edgenesis/shifu/pkg/deviceshifu/deviceshifubase"
"github.com/edgenesis/shifu/pkg/k8s/api/v1alpha1"
)

type DeviceShifu struct {
Expand Down Expand Up @@ -125,7 +126,7 @@ func deviceCommandHandlerSocket(deviceShifuSocketHandlerMetaData *DeviceShifuSoc
connection := deviceShifuSocketHandlerMetaData.connection
command := socketRequest.Command
timeout := socketRequest.Timeout
if timeout != 0 {
if timeout > 0 {
(*connection).SetDeadline(time.Now().Add(time.Duration(timeout) * time.Second))
}

Expand Down

0 comments on commit be4bd7f

Please sign in to comment.