manage http timeout to allow long poll
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
ycc 2024-04-20 22:29:22 +02:00
parent 7c17a11426
commit d14cd161da
4 changed files with 14 additions and 7 deletions

View File

@ -18,9 +18,12 @@ type Config struct {
MaxIdsPerUser int `json:"max_ids_per_user,omitempty"`
MsgDbRollingPeriod int `json:"msg_db_rolling_period,omitempty"`
Chunksize int64 `json:"chunksize,omitempty"`
ServerPollInterval int `json:"server_poll_interval,omitempty"`
DbSize int `json:"db_size,omitempty"`
UserAgent string `json:"user_agent,omitempty"`
// Network
ServerPollInterval int `json:"server_poll_interval,omitempty"`
HttpTimeOut int `json:"http_timeout,omitempty"`
HttpLongPoll int `json:"http_long_poll,omitempty"`
// GUI
LastOpenChat string `json:"last_open_chat,omitempty"`
SoundNotificationEnable bool `json:"sound_notification_enable,omitempty"`

View File

@ -27,7 +27,7 @@ type ReceivedMessage struct {
}
// CheckForMessages checks for messages on a single server
func CheckForMessages(storage_path string, job *client.RequestsJob) (int, string, error) {
func CheckForMessages(storage_path string, job *client.RequestsJob, timeout int) (int, string, error) {
count := 0
@ -68,7 +68,7 @@ func CheckForMessages(storage_path string, job *client.RequestsJob) (int, string
return -1, "CheckMessages: ProcessOutboundMessage", err
}
response, err := meowlib.HttpPostMessage(job.Server.Url, data)
response, err := meowlib.HttpPostMessage(job.Server.Url, data, timeout)
if err != nil {
return -1, "CheckMessages: httpPostMessage", err
}

View File

@ -5,7 +5,7 @@ import (
"forge.redroom.link/yves/meowlib/client"
)
func HttpSendMessage(serverUid string, message []byte) ([]byte, error) {
func HttpSendMessage(serverUid string, message []byte, timeout int) ([]byte, error) {
id := client.GetConfig().GetIdentity()
srv, err := id.MessageServers.LoadServer(serverUid)
if err != nil {
@ -22,7 +22,7 @@ func HttpSendMessage(serverUid string, message []byte) ([]byte, error) {
id.MessageServers.StoreServer(srv)
}
response, err := meowlib.HttpPostMessage(srv.Url, message)
response, err := meowlib.HttpPostMessage(srv.Url, message, timeout)
if err != nil {
return nil, err
}

View File

@ -5,6 +5,7 @@ import (
"encoding/json"
"io"
"net/http"
"time"
)
func HttpGetId(url string) (response map[string]string, err error) {
@ -25,8 +26,11 @@ func HttpGetId(url string) (response map[string]string, err error) {
return srvId, nil
}
func HttpPostMessage(url string, msg []byte) (response []byte, err error) {
resp, err := http.Post(url+"/msg",
func HttpPostMessage(url string, msg []byte, timeout int) (response []byte, err error) {
client := http.Client{
Timeout: time.Duration(timeout) * time.Second,
}
resp, err := client.Post(url+"/msg",
"application/octet-stream", bytes.NewBuffer(msg))
if err != nil {
return nil, err